<!-- 正文开始 -->
<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-card-body">
      <!-- 头部操作栏 -->
      <div class="layui-form lay-header">
        <div class="toolbar">
          <div class="layui-form-item lay-query-content">
            <div class="lay-query-box">
              <div class="query-lt">
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">计划编号：</label>
                  <div class="layui-input-inline">
                    <input name="code" class="layui-input" type="text" placeholder="请输入计划编号" />
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">物料编号：</label>
                  <div class="layui-input-inline">
                    <input name="skuCode" class="layui-input" type="text" placeholder="请输入物料编号" />
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">状态：</label>
                  <div class="layui-input-inline">
                    <select id="status" name="status">
                      <option value="">全部</option>
                      <option value="checkpending">待审核</option>
                      <option value="checked">已审核</option>
                      <option value="toconfirmed">待确认</option>

                      <option value="affirm">已确认</option>

                      <option value="rowproduce">待排产</option>
                      <option value="alreadyrowproduce">已排产</option>
                      <option value="tobeproduced">待生产</option>
                      <option value="inproduction">生产中</option>
                      <option value="accomplish">完成</option>
                      <option value="cancellation">作废</option>
                      <!-- /**
* 待审核
*/
checkpending(0,"待审核"),
/**
* 已审核
*/
checked(1,"已审核"),
/**
* 待排产
*/
rowproduce(2,"待排产"),
/**
* 已排产
*/
alreadyrowproduce(3,"已排产"),
/**
* 待生产
*/
tobeproduced(4,"待生产"),
/**
* 生产中
*/
inproduction(5,"生产中"),
/**
* 完成
*/
accomplish(6,"完成"),
/**
* 作废
*/
cancellation(7,"作废"),
/**
 * 待确认
 */
toconfirmed(8,"待确认"),
/**
 * 已确认
 */
affirm(9,"已确认"); -->
                    </select>
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">创建时间：</label>
                  <div class="layui-input-inline">
                    <input id="pTime" class="layui-input date-icon" type="text" placeholder="请选择创建时间" autocomplete="off" readonly />
                    <input name="startCreateTime" id="sTime" style="display: none" />
                    <input name="endCreateTime" id="eTime" style="display: none" />
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">车间：</label>
                  <div class="layui-input-inline">
                    <!-- <input
                            name="workshopName"
                            class="layui-input"
                            type="text"
                            placeholder="请输入车间"
                    /> -->
                    <select id="workshopId" name="workshopId"></select>
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">计划完工时间：</label>
                  <div class="layui-input-inline">
                    <input name="outputTime" id="outputTime" class="layui-input date-icon" type="text" placeholder="请选择计划完工时间" style="width: 200px" readonly />
                  </div>
                  <input name="startOutputTime" id="sOutputTime" type="hidden" />
                  <input name="endOutputTime" id="eOutputTime" type="hidden" />
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">交付时间：</label>
                  <div class="layui-input-inline">
                    <input name="shipmentTime" id="shipmentTime" class="layui-input date-icon" type="text" placeholder="请选择交付时间" style="width: 200px" readonly />
                  </div>
                  <input name="startShipmentTime" id="sShipmentTime" type="hidden" />
                  <input name="endShipmentTime" id="eShipmentTime" type="hidden" />
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">物料名称：</label>
                  <div class="layui-input-inline">
                    <input name="skuName" class="layui-input" type="text" placeholder="请输入物料名称" />
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">物料规格：</label>
                  <div class="layui-input-inline">
                    <input name="skuSpec" class="layui-input" type="text" placeholder="请输入物料规格" />
                  </div>
                </div>
              </div>
              <div class="query-rt">
                <div class="layui-inline">
                  <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit>查询</button>
                  <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置</button>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="lay-btn-rows">
          <div class="lay-btn-box">
            <div class="lay-btn-lt">
              <!-- <button id="addProductionPlanBtn" class="layui-btn color-reseda" type="button">添加生产计划</button> -->
              <button id="addBtn" class="layui-btn color-reseda" type="button">添加生产</button>
              <!-- <button id="xxxxx" class="layui-btn color-reseda" type="button">xxxxx</button> -->
            </div>
            <div class="lay-btn-rt"></div>
          </div>
        </div>
      </div>
      <!-- 表格 -->
      <table class="layui-table" id="productionPlanTable" lay-filter="productionPlanTable"></table>
    </div>
  </div>
</div>
<style>
  div[lay-id="productionPlanTable"] .layui-table-cell {
    padding: 0 5px;
  }

  .table-auto .layui-table-cell {
    height: auto;
  }

  .template-box .w-auto {
    width: 110px !important;
    text-align: left;
    padding: 9px 0;
  }

  .template-box .addTable {
    height: 30px;
    line-height: 30px;
    padding: 0 10px;
  }

  .msg-none .layui-none {
    display: none !important;
  }

  .flex-item {
    display: flex;
    border-bottom: 1px solid #e6e6e6;
  }

  .left-btn {
    flex: 1;
    text-align: left;
  }

  .flex-between {
    width: calc(100% - 40px);
    display: flex;
    justify-content: space-between;
  }

  body .layui-table tbody tr.disabledBg {
    background-color: #f5f5f5 !important;
  }

  .layui-table-page-left {
    text-align: left;
  }

  .scroll-table-5-4 .layui-table-body {
    max-height: 535px;
  }

  .scroll-table-4-5 .layui-table-body {
    max-height: 490px;
  }

  /*   添加生产计划   */
  .addProductionPlanForm-title,
  .examineProductionPlanForm-title {
    width: 100%;
  }

  .addProductionPlanForm-title .title,
  .examineProductionPlanForm-title .title {
    display: inline-block;
    font-size: 16px;
    font-weight: bold;
    color: #333333;
    line-height: 19px;
    position: relative;
    padding: 6px 0 19px 0;
  }

  .addProductionPlanForm-title .title:after,
  .examineProductionPlanForm-title .title:after {
    content: "";
    display: block;
    position: absolute;
    left: 0;
    bottom: 0;
    width: calc(100% + 6px);
    height: 3px;
    background: #0a8b0a;
  }

  .line {
    width: 100%;
    height: 1px;
    background-color: #f8f8f8;
  }

  .addProductionPlanFormBox {
    padding: 20px 0;
  }

  .addProductionPlanFormBox .layui-col-md4 {
    margin: 5px 0;
  }

  .addProductionPlanFormBox .layui-form-label,
  addProductionPlanFormItem .layui-form-label {
    padding: 9px;
    width: 115px;
    font-size: 14px;
    font-weight: 400;
    color: #999999;
  }

  .addProductionPlanFormBox .layui-input-inline > input[readonly] {
    border-color: rgba(0, 0, 0, 0);
    outline: none;
  }

  .addProductionPlanFormBox .layui-input-inline > input[readonly]:focus,
  .addProductionPlanFormBox .layui-input-inline > input[readonly]:hover {
    border-color: transparent !important;
    outline: none;
  }

  form[lay-filter="examineProductionPlanForm"] textarea {
    width: 90%;
    resize: none;
    padding: 5px 10px;
    height: 100px;
    box-sizing: border-box;
  }

  form[lay-filter="examineProductionPlanForm"] .layui-table-cell {
    height: auto;
  }

  form[lay-filter="examineProductionPlanForm"] .layui-table-cell > img {
    height: 100%;
  }

  .addProductionPlanFormItem {
    padding: 15px 0 0 0;
  }

  .addProductionPlanFormItem .layui-input-block {
    margin-left: 133px;
    padding-right: 90px;
    box-sizing: border-box;
  }

  .open-details-box::-webkit-scrollbar {
    width: 0 !important;
  }
</style>

<!-- 表格操作列 -->
<script type="text/html" id="productionPlanTableBar">
  <!-- {{# if(d.status=="cancellation"){ }} -->
  <a class="layui-btn layui-btn-xs" lay-event="details">详情</a>
  <!-- {{# }else{ }}  -->
  <!-- {{# if( d.status =="checkpending"){ }} -->
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  <!-- {{# } }} -->

  <!-- 订单状态-->
  <!--checkpending(0,待审核);
    checked(1,已审核);
    rowproduce(2,待排产);
    alreadyrowproduce(3,已排产);
    tobeproduced(4,待生产);
    inproduction(5,生产中);
    accomplish(6,完成);-->
  <!--  当订单状态等于以上状态的时候不进行处理  等于其他状态的时候就显示确认提交按钮-->
  <!-- {{# if(d.whetherEdit=="0"&& d.status=="affirm"){ }} 
  {{# }else if(d.whetherEdit=="0"&& d.status=="checkpending"){ }} 
  {{# }else if(d.whetherEdit=="0"&& d.status=="checked"){ }} 
  {{# }else if(d.whetherEdit=="0"&& d.status=="rowproduce"){ }} 
  {{# }else if(d.whetherEdit=="0"&& d.status=="alreadyrowproduce"){ }} 
  {{# }else if(d.whetherEdit=="0"&& d.status=="tobeproduce"){ }} 
  {{# }else if(d.whetherEdit=="0"&& d.status=="inproduction"){ }} 
  {{# }else if(d.whetherEdit=="0"&& d.status=="accomplish"){ }} 
  
  {{# }else { }} -->
  <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="confirmSubmission">确认提交</a>
  <!-- {{# } }} 
   
  {{# if(d.status=="affirm"||d.status=="checkpending"){ }} -->
  <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="examine">审核</a>
  <!-- {{# } }} -->

  <!-- <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="toVoid">作废</a> -->
  <a class="layui-btn layui-btn-xs" lay-event="details">详情</a>
  <!-- {{# if(d.status=='checked' ||d.status=='alreadyrowproduce'){ }} -->
  <!-- {{# if(d.productionPlanHaveQuantity<d.productionQuantity){ }} -->
  <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="plan">计划排产</a>
  <!-- {{# } }} -->
  <a class="layui-btn layui-btn-xs" lay-event="checkPlanRecord">排产记录</a>

  <!-- {{# } }} -->

  <!-- {{# if(d.whetherProduction=="0" && d.checkStatus=='approve'){ }} -->
  <!-- {{# if(d.productionQuantity - d.productionPlanHaveQuantity == 0) { }} -->
  <!-- {{# } }} -->
  <!-- {{# } }}  -->
  <!-- {{# if(d.whetherProduction=="0" && d.status=='alreadyrowproduce'){ }} -->
  <!-- {{# } }}  -->
  <!-- {{# } }} -->
</script>
<!--关联物料表格操作列-->
<script type="text/html" id="relevanceMaterialTableBar">
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<!--台机排产表格操作列-->
<script type="text/html" id="deviceProductionTableBar1">
  <!-- <a class="layui-btn layui-btn-xs" lay-event="detail">明细</a> -->
  <!-- {{# if(d.status=="no"){ }} -->
  <!-- <a class="layui-btn layui-btn-xs" lay-event="save">保存</a> -->
  <!-- {{# }else if(d.status =="yes"){ }} -->
  <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit">修改</a>
  <!-- {{# } }} -->
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<!--生产计划排产顶部表格-->
<!--<script type="text/html" id="productionPlanModelTableBar">-->
<!--    <button class="layui-btn layui-btn-danger" lay-filter="productionPlanFormSubmit" lay-submit>提交排产计划</button>-->
<!--</script>-->

<!-- 生产计划排产表单 -->
<script type="text/html" id="productionPlanForm">
  <form lay-filter="productionPlanForm" class="layui-form open-form">
    <div class="open-model">
      <div class="open-auto">
        <div class="layui-form-item table-bor table-auto">
          <table class="layui-table" id="detailProductionPlanTable" lay-filter="detailProductionPlanTable"></table>
        </div>
        <div class="layui-tab" id="productionPlanBox" lay-filter="productionPlanBox" lay-allowclose="true">
          <div class="flex-item">
            <ul class="layui-tab-title br0" id="processNodsTitle"></ul>
            <!--                    <button id="addProcessNods" class="layui-btn" type="button" style="margin-left: 20px;">增加工序节点-->
            <!--                    </button>-->
          </div>

          <div class="layui-tab-content" id="processNodsContent"></div>
        </div>
      </div>
      <div class="layui-form-item text-right flex-between">
        <!-- <div class="left-btn">
          <div class="isData" style="display: none">
            <button id="saveProcessPlan" class="layui-btn" type="button">保存工序排产计划</button>
          </div>
        </div> -->
        <div class="right-btn">
          <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
          <button class="layui-btn" lay-filter="productionPlanFormSubmit" lay-submit>提交</button>
        </div>
      </div>
    </div>
  </form>
</script>
<!--增加工序节点模板-->
<script id="processNodsTitleTemplate" type="text/html">
  <!-- {{# layui.each(d, function(index, item){ }} -->
  <li lay-id="{{index}}">
    {{item.title }}
    <!--        <i class="layui-icon layui-icon-close layui-unselect layui-tab-close"></i>-->
  </li>
  <!-- {{# }) }} -->
</script>
<script id="processNodsContentTemplate" type="text/html">
  <!-- {{# layui.each(d, function(index, item){ }} -->
  <div class="layui-tab-item">
    <div class="" data-id="{{index}}">
      <div class="layui-row">
        <div class="layui-col-xs3" style="width: 33%; ">
          <div class="layui-form-item">
            <label class="layui-form-label w-auto">工序编码</label>
            <div class="layui-input-inline">
              <input name="productionQuantity" class="layui-input text-red br0" type="text" value="{{item.code}}" readonly="readonly" />
            </div>
          </div>
        </div>
        <!-- <div class="layui-col-xs3" style="width: 33%; ">
          <div class="layui-form-item">
            <label class="layui-form-label w-auto">已排产数量</label>
            <div class="layui-input-inline">
              <input name="productionQuantity" class="layui-input text-red br0" type="text" value="{{item.productionQuantity}}" readonly="readonly" />
            </div>
          </div>
        </div>
        <div class="layui-col-xs3" style="width: 33%;">
          <div class="layui-form-item">
            <label class="layui-form-label w-auto">平均合格率</label>
            <div class="layui-input-inline">
              <input name="yield" class="layui-input text-red br0" type="text" value="{{item.yield}}%" readonly="readonly" />
            </div>
          </div>
        </div> -->
        <div class="layui-col-xs3" style="width: 33%;">
          <div class="layui-form-item">
            <label class="layui-form-label w-auto">工资定额(元)</label>
            <div class="layui-input-inline">
              <input name="yield" class="layui-input text-red br0" type="text" value="{{item.salaryQuota}}" readonly="readonly" />
              <!-- <select name="pieceRateStatus{{index}}" lay-filter="pieceRateStatus{{index}}" lay-verify="required">
                <option value="yes">启用计件工资</option>
                <option value="no">不用计件工资</option>
              </select> -->
            </div>
          </div>
        </div>
        <!-- <div class="layui-col-xs3" id="isPieceRate{{index}}" style="width: 22%;">
          <div class="layui-form-item">
            <label class="layui-form-label w-auto">计件工资</label>
            <div class="layui-input-inline">
              <input name="pieceRate" class="layui-input pieceRate" type="text" value="{{item.pieceRate}}" lay-verify="required" />
            </div>
          </div>
        </div> -->
      </div>
      <div class="layui-row table-bor msg-none" style="margin-top: 15px;">
        <div class="layui-col-md7" style="padding-right: 25px">
          <div class="layui-form-item" style="margin-bottom: 10px;">
            <div class="open-details-title">机台排产</div>
          </div>
          <table class="layui-table" id="deviceProductionTable{{index}}" lay-filter="deviceProductionTable{{index}}"></table>
          <button class="layui-btn addTable addDeviceProduction" type="button">添加排产设备</button>
        </div>
        <div class="layui-col-md5">
          <div class="layui-form-item" style="margin-bottom: 10px;">
            <div class="open-details-title">关联物料</div>
          </div>
          <button class="layui-btn addTable addRelevanceMaterial" type="button">添加排产物料</button>
          <table class="layui-table" id="relevanceMaterialTable{{index}}" lay-filter="relevanceMaterialTable{{index}}"></table>
        </div>
      </div>
    </div>
  </div>
  <!-- {{# }) }} -->
</script>
<!--排产计划详情-->
<script id="checkProductionPlanTemplate" type="text/html">
  <form lay-filter="checkProductionPlanForm" class="layui-form model-form form-scroll">
    <div class="open-details-box pd-20">
      <div class="layui-form-item table-bor table-auto">
        <table class="layui-table" id="checkProductionPlanTable" lay-filter="checkProductionPlanTable"></table>
      </div>
      <div class="layui-tab" id="checkProductionPlan" lay-filter="checkProductionPlan" style="display: none;">
        <div class="flex-item">
          <ul class="layui-tab-title br0" id="checkProcessNodsTitle"></ul>
        </div>

        <div class="layui-tab-content" id="checkProcessNodsContent" lay-filter="checkProcessNodsContent">
          <div class="template-box" data-id="{{index}}">
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label w-auto">已排产数量</label>
                <div class="layui-input-inline">
                  <input name="checkQuantity" class="layui-input text-red br0" type="text" value="" readonly="readonly" />
                </div>
              </div>
            </div>
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label w-auto">平均合格率</label>
                <div class="layui-input-inline">
                  <input name="checkRate" class="layui-input text-red br0" type="text" value="" readonly="readonly" />
                </div>
              </div>
            </div>

            <div class="layui-row table-bor msg-none" style="margin-top: 15px;">
              <div class="layui-col-md7">
                <div class="layui-form-item" style="margin-bottom: 0;">
                  <div class="open-details-title">机台排产</div>
                </div>
                <table class="layui-table" id="checkDeviceProductionTable" lay-filter="checkDeviceProductionTable"></table>
              </div>
              <div class="layui-col-md5">
                <div class="layui-form-item" style="margin-bottom: 0;">
                  <div class="open-details-title">关联物料</div>
                </div>
                <table class="layui-table" id="checkRelevanceMaterialTable" lay-filter="checkRelevanceMaterialTable"></table>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="layui-form-item text-right pd-20">
      <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
    </div>
  </form>
</script>
<script id="checkProcessNodsTitleTemplate" type="text/html">
  <!-- {{# layui.each(d, function(index, item){ }} -->
  <li lay-id="{{index}}" process-id="{{item.id}}">{{item.title}}</li>
  <!-- {{# }) }} -->
</script>

<!--选择工序-->
<script type="text/html" id="selectProcessListAdd">
  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-body">
        <!-- 头部操作栏 -->
        <div class="layui-form toolbar">
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label w-auto">工序编号：</label>
              <div class="layui-input-inline mr0" style="width: 240px;">
                <input name="code" class="layui-input" type="text" placeholder="工序编号" />
              </div>
            </div>
            <div class="layui-inline">
              <button class="layui-btn icon-btn" lay-filter="selectStorageSignListAddFormSubSearchLog" lay-submit style="padding: 0 24px;">搜索</button>
              <button id="selectStorageSignListAddClose" class="layui-btn icon-btn">确认选择</button>
            </div>
          </div>
        </div>

        <!-- 表格 -->
        <table class="layui-table" id="selectStorageSignListAddTable" lay-filter="selectStorageSignListAddTable"></table>
      </div>
    </div>
  </div>
</script>
<!--选择设备-->
<script type="text/html" id="selectProcessDeviceByProcessId">
  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-body">
        <!-- 头部操作栏 -->
        <div class="layui-form toolbar">
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label w-auto">设备编码</label>
              <div class="layui-input-inline mr0" style="width: 240px;">
                <input name="deviceCode" class="layui-input" type="text" placeholder="请输入设备编码" />
              </div>
            </div>
            <div class="layui-inline">
              <button class="layui-btn icon-btn" lay-filter="selectProcessFormSubSearchLog" lay-submit style="padding: 0 24px;">搜索</button>
              <button id="selectProcessDeviceByProcessIdClose" class="layui-btn icon-btn">确认选择</button>
            </div>
          </div>
        </div>
        <!-- 表格 -->
        <div class="scroll-table-4-5">
          <table class="layui-table" id="selectProcessDeviceByProcessIdTable" lay-filter="selectProcessDeviceByProcessIdTable"></table>
        </div>
      </div>
    </div>
  </div>
</script>
<!--选择物料-->
<script type="text/html" id="selectProcessMaterialPageList">
  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-body">
        <!-- 头部操作栏 -->
        <div class="layui-form toolbar">
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label w-auto">物料编码：</label>
              <div class="layui-input-inline mr0" style="width: 240px;">
                <input name="skuCode" class="layui-input" type="text" placeholder="请输入物料编码" />
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label w-auto">物料规格：</label>
              <div class="layui-input-inline mr0" style="width: 240px;">
                <input name="skuSpec" class="layui-input" type="text" placeholder="请输入物料规格" />
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label w-auto">物料类别</label>
              <div class="layui-input-inline">
                <input name="productTypeId" type="hidden" />
                <div class="layui-input-inline mr0" id="selectProductType"></div>
              </div>
            </div>
            <div class="layui-inline">
              <button class="layui-btn icon-btn" lay-filter="selectProcessMaterialPageListFormSubSearchLog" lay-submit style="padding: 0 24px;">搜索</button>
            </div>
          </div>
        </div>
        <!-- 表格 -->
        <div class="scroll-table-4-5">
          <table class="layui-table" id="selectProcessMaterialPageListTable" lay-filter="selectProcessMaterialPageListTable"></table>
        </div>
        <div class="layui-form-item text-right" style="padding-top: 10px;">
          <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
          <button id="selectProcessMaterialPageListClose" class="layui-btn">确认选择</button>
        </div>
      </div>
    </div>
  </div>
</script>

<!--机台排产开工单-->
<script id="deviceWorkOrderTemplate" type="text/html">
  <div class="layui-form model-form form-scroll">
    <div class="open-details-box pd-20">
      <div class="lay-header" style="padding-top: 25px;">
        <div class="layui-form-item">
          <div class="lay-query-box">
            <div class="query-lt">
              <div class="layui-inline">
                <label class="layui-form-label w-auto">工单编号：</label>
                <div class="layui-input-inline">
                  <input name="code" class="layui-input" type="text" placeholder="工单编号" />
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label w-auto">计划编号：</label>
                <div class="layui-input-inline">
                  <input name="planCode" class="layui-input" type="text" placeholder="计划编号" />
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label w-auto">物料名称：</label>
                <div class="layui-input-inline">
                  <input name="skuName" class="layui-input" type="text" placeholder="物料名称" />
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label w-auto">物料编码：</label>
                <div class="layui-input-inline">
                  <input name="skuCode" class="layui-input" type="text" placeholder="物料编码" />
                </div>
              </div>
              <!--状态:toactivate(0,待激活);inproduction(1,生产中);accomplish(2,完成);termination(3,终止完成)-->
              <div class="layui-inline">
                <label class="layui-form-label w-auto">工单状态：</label>
                <div class="layui-input-inline">
                  <select name="status">
                    <option value="">工单状态</option>
                    <option value="toactivate">待激活</option>
                    <option value="inproduction">生产中</option>
                    <option value="accomplish">完成</option>
                    <option value="termination">终止完成</option>
                  </select>
                </div>
              </div>
            </div>
            <div class="query-rt">
              <div class="layui-inline">
                <button class="layui-btn icon-btn color-green" lay-filter="deviceWorkOrderFormSubSearchLog" lay-submit>查询</button>
                <button class="layui-btn icon-btn color-white" lay-filter="deviceWorkOrderResets" lay-submit>重置</button>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="layui-form-item">
        <table class="layui-table" id="deviceWorkOrderTable" lay-filter="deviceWorkOrderTable"></table>
      </div>
    </div>
    <div class="layui-form-item text-right pd-20">
      <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
    </div>
  </div>
</script>
<!--表格操作按钮-->
<script type="text/html" id="deviceWorkOrderTableBar">
  <a class="layui-btn layui-btn-xs" lay-event="detail">详情</a>
  <!-- {{# if(d.status=="toactivate"){ }} -->
  <a class="layui-btn layui-btn-xs" lay-event="activate">激活</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="close">关闭</a>
  <!-- {{# }else if(d.status =="inproduction"){ }} -->
  <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="pause">暂停</a>
  <!-- {{# }else if(d.status =="termination"){ }} -->
  <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="activate">激活</a>
  <!-- {{# } }} -->
  <a class="layui-btn layui-btn-xs" lay-event="up">上移</a>
  <a class="layui-btn layui-btn-xs" lay-event="down">下移</a>
</script>

<!--开工单详情-->
<script id="getWorkOrderInfoTemplate" type="text/html">
  <form lay-filter="getWorkOrderInfoForm" class="layui-form model-form form-scroll">
    <div class="open-details-box pd-20">
      <div class="work-info" style="padding-top: 25px;">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label w-auto">工单编号：</label>
            <div class="layui-input-inline">
              <input name="workOrderCode" class="layui-input br0" type="text" readonly="readonly" />
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label w-auto">所属计划：</label>
            <div class="layui-input-inline">
              <input name="planCode" class="layui-input br0" type="text" readonly="readonly" />
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label w-auto">交货时间：</label>
            <div class="layui-input-inline">
              <input name="deliveryTime" class="layui-input br0" type="text" readonly="readonly" />
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label w-auto">订单录入人：</label>
            <div class="layui-input-inline">
              <input name="keyboarder" class="layui-input br0" type="text" readonly="readonly" />
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label w-auto">询价审核人：</label>
            <div class="layui-input-inline">
              <input name="enquiryAuditPerson" class="layui-input br0" type="text" readonly="readonly" />
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label w-auto">报价截止时间：</label>
            <div class="layui-input-inline">
              <input name="expirationDate" class="layui-input br0" type="text" readonly="readonly" />
            </div>
          </div>
        </div>
      </div>
      <div class="layui-form-item table-bor">
        <div class="layui-form-item" style="margin-bottom: 0;">
          <div class="open-details-title">工序排产明细</div>
        </div>
        <table class="layui-table" id="workInfoPlanDetailTable" lay-filter="workInfoPlanDetailTable"></table>
      </div>
      <div class="layui-form-item table-bor">
        <table class="layui-table" id="workInfoWorkOrderDetailTable" lay-filter="workInfoWorkOrderDetailTable"></table>
      </div>
      <div class="layui-form-item table-bor">
        <div class="layui-form-item" style="margin-bottom: 0;">
          <div class="open-details-title">工序关联物料明细</div>
        </div>
        <table class="layui-table" id="workInfoMaterialDetailTable" lay-filter="workInfoWorkOrderDetailTable"></table>
      </div>
    </div>
    <div class="layui-form-item text-right pd-20">
      <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
    </div>
  </form>
</script>

<!--添加生产计划-->
<!--addProductionPlanForm-->
<script type="text/html" id="addProductionPlanForm">
  <form lay-filter="addProductionPlanForm" class="layui-form open-form">
    <div class="open-model">
      <div class="open-auto">
        <input type="hidden" name="id" />
        <input type="hidden" name="productTypeName" />
        <div class="layui-form-item">
          <div class="addProductionPlanForm-title">
            <h3 class="title">计划信息</h3>
          </div>
          <div class="line"></div>
          <div class="layui-form-item layui-row addProductionPlanFormBox">
            <div class="layui-inline layui-col-md4">
              <label class="layui-form-label">计划来源：</label>
              <div class="layui-input-inline">
                <select id="planSource" name="planSource" lay-filter="planSource"></select>
              </div>
            </div>
            <div class="layui-inline layui-col-md4" id="orderTypeBox">
              <label class="layui-form-label">订单类型：</label>
              <div class="layui-input-inline">
                <select id="orderType" name="orderType" lay-verify="required"></select>
              </div>
            </div>
            <div class="layui-inline layui-col-md4" id="orderIdBox">
              <label class="layui-form-label">订单编号：</label>
              <div class="layui-input-inline">
                <select id="orderId" name="orderId" lay-filter="orderId" lay-search="" lay-verify="required"></select>
              </div>
            </div>
            <div class="layui-inline layui-col-md4">
              <label class="layui-form-label">计划分类：</label>
              <div class="layui-input-inline">
                <input name="planClassifyId" type="hidden" />
                <div class="layui-input-block" id="selectPlanClassify" style="margin-left: 0px;"></div>
              </div>
            </div>
            <div class="layui-inline layui-col-md4">
              <label class="layui-form-label">计划类型：</label>
              <div class="layui-input-inline">
                <select name="planTypeId" lay-search="" lay-verify="required"></select>
              </div>
            </div>
            <div class="layui-inline layui-col-md4">
              <label class="layui-form-label">计划性质：</label>
              <div class="layui-input-inline">
                <select id="planNature" name="planNature" lay-filter="planNature"></select>
              </div>
            </div>

            <div class="layui-inline layui-col-md4" id="creatorNameBox">
              <label class="layui-form-label">计划创建人：</label>
              <div class="layui-input-inline">
                <input name="creatorName" class="layui-input" type="text" readonly />
              </div>
            </div>
            <div class="layui-inline layui-col-md4" id="phoneBox">
              <label class="layui-form-label">创建人电话：</label>
              <div class="layui-input-inline">
                <input name="phone" class="layui-input" type="text" readonly />
              </div>
            </div>
            <div class="layui-inline layui-col-md4" id="auditPersonBox">
              <label class="layui-form-label">计划审核人：</label>
              <div class="layui-input-inline">
                <input name="auditPerson" class="layui-input" type="text" readonly />
              </div>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="addProductionPlanForm-title">
            <h3 class="title">计划生产物料信息</h3>
          </div>
          <div class="line"></div>
          <div class="layui-form-item layui-row addProductionPlanFormBox">
            <div class="layui-inline layui-col-md4" id="signOrNotBox" style="display: none">
              <label class="layui-form-label">是否已签约：</label>
              <div class="layui-input-inline">
                <!-- <select name="signOrNot" lay-filter="signOrNot">
                                     <option value="yes">已签约</option>
                                     <option value="no">未签约</option>
                                 </select>-->
                <!--                            <input name="signOrNot" type="hidden"/>-->
                <input name="signOrNotDesc" class="layui-input" type="text" readonly />
              </div>
            </div>
            <div class="layui-inline layui-col-md4" id="contractIdBox" style="display: none">
              <label class="layui-form-label">选择所属合同：</label>
              <div class="layui-input-inline">
                <!--                            <select name="contractId" id="contractId" lay-search="" lay-verify="required"></select>-->
                <input name="contractId" type="hidden" />
                <input name="contractName" class="layui-input" type="text" readonly />
              </div>
            </div>
            <div class="layui-inline layui-col-md4" id="orderCreatorNameBox">
              <label class="layui-form-label">订单录入人：</label>
              <div class="layui-input-inline">
                <input name="orderCreatorName" class="layui-input" type="text" readonly />
              </div>
            </div>
            <div class="layui-inline layui-col-md4">
              <label class="layui-form-label">物料编号：</label>
              <div class="layui-input-inline">
                <input name="customerSkuCode" id="customerSkuCode" class="layui-input" type="text" />
                <input name="orderProId" class="layui-input" type="hidden" />
              </div>
            </div>
            <div class="layui-inline layui-col-md4">
              <label class="layui-form-label">基准书：</label>
              <div class="layui-input-inline">
                <select name="bookId" lay-filter="bookId" id="bookId"></select>
              </div>
            </div>
            <div class="layui-inline layui-col-md4">
              <label class="layui-form-label">物料类型：</label>
              <div class="layui-input-inline">
                <!--                            <select name="productTypeId" lay-filter="addProductionPlanFormProductTypeId" disabled></select>-->
                <input name="productTypeId" type="hidden" />
                <input name="productTypeName" class="layui-input" type="text" disabled />
              </div>
            </div>
            <div class="layui-inline layui-col-md4" id="processIdBox">
              <label class="layui-form-label">选择工序：</label>
              <div class="layui-input-inline">
                <select name="processId" id="processId" lay-filter="processId" lay-search="" lay-verify="required"></select>
              </div>
            </div>
            <div class="layui-inline layui-col-md4">
              <label class="layui-form-label">物料名称：</label>
              <div class="layui-input-inline">
                <input name="customerSkuName" class="layui-input" type="text" disabled />
              </div>
            </div>
            <div class="layui-inline layui-col-md4">
              <label class="layui-form-label">物料规格码：</label>
              <div class="layui-input-inline">
                <input name="customerSkuSpec" class="layui-input" type="text" disabled />
              </div>
            </div>
            <div class="layui-inline layui-col-md4" id="residueQuantityBox">
              <label class="layui-form-label">订单剩余计划量：</label>
              <div class="layui-input-inline">
                <input name="residueQuantity" class="layui-input" type="text" disabled />
              </div>
            </div>

            <div class="layui-inline layui-col-md4" id="">
              <label class="layui-form-label">交货时间：</label>
              <div class="layui-input-inline">
                <input name="shipmentTime" class="layui-input" type="text" id="addProductionPlanDeliveryTime" lay-verify="required" />
              </div>
            </div>
            <div class="layui-inline layui-col-md4">
              <label class="layui-form-label">需求数量：</label>
              <div class="layui-input-inline">
                <input name="demandQuantity" class="layui-input" type="text" lay-verify="number" />
              </div>
            </div>
            <div class="layui-inline layui-col-md4">
              <label class="layui-form-label">计划生产数量：</label>
              <div class="layui-input-inline">
                <input name="productionQuantity" class="layui-input" type="text" lay-verify="number" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" />
              </div>
            </div>
            <div class="layui-inline layui-col-md4">
              <label class="layui-form-label">计划产出时间：</label>
              <div class="layui-input-inline">
                <input name="outputTime" class="layui-input" type="text" id="plannedOutputTime" autocomplete="off" lay-verify="required" />
              </div>
            </div>
            <div class="layui-form-item addProductionPlanFormItem" id="orderRemarkBox">
              <label class="layui-form-label">订单备注描述：</label>
              <div class="layui-input-block">
                <input name="orderRemark" class="layui-input" type="text" readonly />
              </div>
            </div>
            <div class="layui-form-item addProductionPlanFormItem">
              <label class="layui-form-label">上传附件：</label>
              <div class="layui-input-block">
                <div id="accessoryPath" class="uploadImgStyle" style="line-height: 38px"></div>
                <div id="accessoryBtn" class="layui-btn" style="float: left;margin-left: 3px">上传附件</div>
                <input name="accessory" type="hidden" id="accessoryFileId" lay-verify="required" lay-reqText="请添加附件" />
              </div>
            </div>
            <div class="layui-form-item addProductionPlanFormItem">
              <label class="layui-form-label">备注说明：</label>
              <div class="layui-input-inline">
                <input name="remark" class="layui-input" type="text" />
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="layui-form-item text-right">
        <button class="layui-btn" lay-filter="addProductionPlanExamine" lay-submit>确认提交</button>
        <button class="layui-btn color-reseda" lay-filter="addProductionPlanFormSubmit" lay-submit>暂时保存</button>
      </div>
    </div>
  </form>
</script>

<!--生产计划审核界面 生产计划详情界面 -->
<!--examineProductionPlanForm-->
<script type="text/html" id="examineProductionPlanForm">
  <form lay-filter="examineProductionPlanForm" class="layui-form open-form">
    <div class="open-model">
      <div class="open-auto">
        <div class="examineProductionPlanForm-title">
          <h3 class="title">订单信息</h3>
        </div>
        <div class="line" style="margin-bottom: 15px;"></div>
        <div class="layui-col-xs3">
          <div class="layui-form-item">
            <label class="layui-form-label">订单来源</label>
            <div class="layui-input-inline">
              <input name="planSourceDesc" class="layui-input" type="text" readonly />
            </div>
          </div>
        </div>
        <div class="layui-col-xs3" id="orderTypeDiv">
          <div class="layui-form-item">
            <label class="layui-form-label">订单类型</label>
            <div class="layui-input-inline">
              <input name="orderTypeDesc" class="layui-input" type="text" readonly />
            </div>
          </div>
        </div>
        <div class="layui-col-xs3">
          <div class="layui-form-item" id="orderCodeDiv">
            <label class="layui-form-label">订单编号</label>
            <div class="layui-input-inline">
              <input name="orderCode" class="layui-input" type="text" readonly />
            </div>
          </div>
        </div>
        <div class="layui-col-xs3" id="signOrNotDiv">
          <div class="layui-form-item">
            <label class="layui-form-label">是否签约</label>
            <div class="layui-input-inline">
              <input name="signOrNotDesc" class="layui-input" type="text" readonly />
            </div>
          </div>
        </div>
        <div class="layui-col-xs3" id="contractDiv">
          <div class="layui-form-item">
            <label class="layui-form-label">所属合同</label>
            <div class="layui-input-inline">
              <input name="contractName" class="layui-input" type="text" readonly />
            </div>
          </div>
        </div>
        <div class="layui-col-xs3">
          <div class="layui-form-item">
            <label class="layui-form-label">物料类型</label>
            <div class="layui-input-inline">
              <input name="productTypeName" class="layui-input" type="text" readonly />
            </div>
          </div>
        </div>
        <div class="layui-col-xs3">
          <div class="layui-form-item">
            <label class="layui-form-label">物料编码</label>
            <div class="layui-input-inline">
              <input name="customerSkuCode" class="layui-input" type="text" readonly />
            </div>
          </div>
        </div>
        <div class="layui-col-xs3">
          <div class="layui-form-item">
            <label class="layui-form-label">物料名称</label>
            <div class="layui-input-inline">
              <input name="customerSkuName" class="layui-input" type="text" readonly />
            </div>
          </div>
        </div>
        <div class="layui-col-xs3">
          <div class="layui-form-item">
            <label class="layui-form-label">物料规格</label>
            <div class="layui-input-inline">
              <input name="customerSkuSpec" class="layui-input" type="text" readonly />
            </div>
          </div>
        </div>
        <div class="layui-col-xs3">
          <div class="layui-form-item">
            <label class="layui-form-label">交货时间</label>
            <div class="layui-input-inline">
              <input name="shipmentTime" class="layui-input" type="text" readonly />
            </div>
          </div>
        </div>
        <div class="layui-col-xs3">
          <div class="layui-form-item">
            <label class="layui-form-label">录入人</label>
            <div class="layui-input-inline">
              <input name="creatorName" class="layui-input" type="text" readonly />
            </div>
          </div>
        </div>
        <div class="layui-col-xs3">
          <div class="layui-form-item">
            <label class="layui-form-label">提交时间</label>
            <div class="layui-input-inline">
              <input name="createTime" class="layui-input" type="text" readonly />
            </div>
          </div>
        </div>

        <!-- <div class="layui-form-item">
          <div class="layui-col-xs3">
            <label class="layui-form-label">图纸/附件</label>
            <div class="layui-input-inline">
              <input type="hidden" name="accessory" id="accessory" value="" />
              <img src="" style="height: 80px;width: 100px" id="accessoryImg" />
            </div>
          </div>
        </div> -->

        <div class="layui-form-item">
          <div class="examineProductionPlanForm-title">
            <h3 class="title">计划信息</h3>
          </div>
          <div class="line"></div>
          <div class="layui-form-item">
            <!-- 计划表格 -->
            <table class="layui-table" id="examineProductionPlanTable" lay-filter="examineProductionPlanTable"></table>
          </div>
        </div>
        <div class="layui-form-item" id="examineBox">
          <div class="examineProductionPlanForm-title">
            <h3 class="title">审核信息</h3>
          </div>
          <div class="line"></div>
          <br />
          <div class="layui-form-item">
            <div class="layui-col-xs6">
              <label class="layui-form-label">审核结果</label>
              <div class="layui-input-inline">
                <select name="checkStatus" lay-filter="">
                  <option value="">请选择审核状态</option>
                  <option value="approve">审核通过</option>
                  <option value="reject">驳回</option>
                </select>
              </div>
            </div>
          </div>
          <div class="layui-form-item">
            <div class="layui-col-xs6">
              <label class="layui-form-label">备注</label>
              <div class="layui-input-block">
                <textarea name="remark" placeholder="请输入备注"></textarea>
              </div>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="examineProductionPlanForm-title">
            <h3 class="title">历史审核记录</h3>
          </div>
          <div class="line"></div>
          <div class="layui-form-item">
            <!-- 计划表格 -->
            <table class="layui-table" id="auditRecordsTable" lay-filter="auditRecordsTable"></table>
          </div>
        </div>
      </div>
      <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        <button class="layui-btn" lay-filter="examineProductionPlanFormSubmit" lay-submit>提交</button>
      </div>
    </div>
  </form>
</script>

<!-- 表格操作列 -->
<script type="text/html" id="productionPlanRecordTableBar">
  <a class="layui-btn layui-btn-xs" lay-event="checkPlan">详情</a>
</script>

<!--排产记录列表-->
<script id="productionPlanRecordList" type="text/html">
  <form lay-filter="productionPlanRecordList" class="layui-form model-form open-form">
    <div class="open-model">
      <div class="open-auto" style="padding-top: 5px;">
        <table class="layui-table" id="productionRecordTable" lay-filter="productionRecordTable"></table>
      </div>
      <div class="layui-form-item text-right pd-20">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
      </div>
    </div>
  </form>
</script>
<!-- js部分 -->
<script>
  layui.use(["layer", "form", "table", "admin", "laydate", "laytpl", "element", "upload"], async function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var config = layui.config;
    var admin = layui.admin;
    var laydate = layui.laydate;
    var laytpl = layui.laytpl;
    var element = layui.element;
    var upload = layui.upload;
    let processList = [];
    let where = {};

    let nowData = {};
    if (typeof parentData !== "undefined") {
      nowData = { ...parentData };
      if (nowData.eventName == "radio" || nowData.eventName == "checkbox") {
        $("#configFun").show();
      }
      if (nowData.where) {
        where = { ...nowData.where };
      }
      if (nowData.eventName == "planHis") {
        $("#addBtn").hide();
      }
    }
    const deviceRes = await admin.initDataSelectPro("enterprise/device/admin/deviceWorkshop/list", {}, "workshopId", "车间", () => {}, "name");
    //时间范围
    laydate.render({
      elem: "#pTime",
      type: "date",
      range: true,
      done: function (value, date, endDate) {
        if (value) {
          var dateValue = value.split(" - ");
          $("input[name='startCreateTime']").val(dateValue[0] + " 00:00:00");
          $("input[name='endCreateTime']").val(dateValue[1] + " 23:59:59");
        } else {
          $("input[name='startCreateTime']").val("");
          $("input[name='endCreateTime']").val("");
        }
      }
    });
    laydate.render({
      elem: "#outputTime",
      type: "date",
      range: true,
      done: function (value, date, endDate) {
        if (value) {
          var dateValue = value.split(" - ");
          $("input[name='startOutputTime']").val(dateValue[0] + " 00:00:00");
          $("input[name='endOutputTime']").val(dateValue[1] + " 23:59:59");
        } else {
          $("input[name='startOutputTime']").val("");
          $("input[name='endOutputTime']").val("");
        }
      }
    });
    laydate.render({
      elem: "#shipmentTime",
      type: "date",
      range: true,
      done: function (value, date, endDate) {
        if (value) {
          var dateValue = value.split(" - ");
          $("input[name='startShipmentTime']").val(dateValue[0] + " 00:00:00");
          $("input[name='endShipmentTime']").val(dateValue[1] + " 23:59:59");
        } else {
          $("input[name='startShipmentTime']").val("");
          $("input[name='endShipmentTime']").val("");
        }
      }
    });
    //生产计划状态
    // admin.getDictList(
    //   "status",
    //   "production_plan_status",
    //   null,
    //   "生产计划状态"
    // );
    let a = [];

    // 渲染表格
    var insTb = table.render({
      elem: "#productionPlanTable",
      url: config.base + "production/productionPlan/admin/productionPlan/list",
      page: true,
      cellMinWidth: 100,
      where: where,
      cols: [
        [
          { type: "numbers", title: "序号" },
          { field: "code", title: "计划编号", align: "center", width: 160 },
          { field: "planTypeName", title: "生产计划类型", align: "center" },
          { field: "orderCode", title: "订单编号", align: "center" },
          // { field: "orderTypeDesc", title: "计划订单类型", align: "center" },
          { field: "customerSkuCode", title: "生产物料", align: "center" },
          { field: "customerSkuName", title: "物料名称", align: "center" },
          { field: "customerSkuSpec", title: "物料规格", align: "center" },
          { field: "workshopName", title: "车间", align: "center" },
          // { field: "productTypeName", title: "所属物料系列", align: "center" },
          { field: "productionQuantity", title: "生产数量", align: "center" },
          {
            field: "productionPlanHaveQuantity",
            title: "已排产数量",
            align: "center"
          },
          {
            title: "剩余排产数量",
            align: "center",
            templet: function (d) {
              return d.productionQuantity - d.productionPlanHaveQuantity <= 0 ? 0 : d.productionQuantity - d.productionPlanHaveQuantity;
            }
          },

          // , {field: 'customerName', title: '客户信息', align: 'center'}
          {
            field: "orderCode",
            title: "订单编号",
            align: "center",
            templet: function (d) {
              return d.orderCode ? d.orderCode : "无";
            }
          },
          { field: "bookCode", title: "基准书", align: "center", width: 160 },
          // { field: 'shipmentTime', title: '交货时间', align: 'center', width: 160 },
          { field: "statusDesc", title: "状态", align: "center" },
          { field: "createTime", title: "创建时间", align: "center" },
          {
            align: "center",
            toolbar: "#productionPlanTableBar",
            title: "操作",
            width: 280,
            fixed: "right"
          }
        ]
      ],
      done: function (res, curr, count) {
        a = table.cache["productionPlanTable"];
      }
    });

    // 工具条点击事件
    table.on("tool(productionPlanTable)", function (obj) {
      var data = obj.data;
      console.log(a);
      if (obj.event === "detail") {
        //修改
        showEditModel(data);
      } else if (obj.event === "plan") {
        //计划排产
        // productionPlanModel(data);
        admin.formOpen({
          area: ["85%", "90%"],
          title: "生产计划排产",
          path: "components/productionPlan/productionPlanningForm.html",
          success: function () {
            parentData.eventName = "plan";
            // parentData.id = data.id;
            parentData.data = data;
          }
        });
      } else if (obj.event === "checkPlanRecord") {
        productionPlanRecordList(data);
      } else if (obj.event === "edit") {
        // 编辑生产计划
        // addProductionPlan(data, 'edit');

        openForm("edit", data.id);
      } else if (obj.event === "examine") {
        // 审核生产计划
        examineProductionPlanModel(data, "examine");
      } else if (obj.event === "details") {
        // 生产计划详情
        // examineProductionPlanModel(data, "details");
        openForm("detail", data.id);
      } else if (obj.event === "confirmSubmission") {
        //确认提交
        // addProductionPlan(data, "confirmSubmission");
        // 弹是否确认提交
        layer.open({
          title: "确认提交",
          content: "确认提交后，生产计划将无法修改",
          btn: ["确认", "取消"],
          yes: function () {
            // addProductionPlan(data, "confirmSubmission");
            // layer.msg("确认提交后，生产计划将无法修改", { icon: 2 });
            admin.req(
              "production/productionPlan/admin/productionPlan/affirm/" + data.id,
              {},
              function (res) {
                if (res.code == 200) {
                  layer.msg("确认提交成功", { icon: 1 });
                  table.reload("productionPlanTable");
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              "PUT"
            );
          }
        });
      } else if (obj.event === "toVoid") {
        // 作废
        toVoidToolCabinet(data);
      }
    });

    //监听排序
    table.on("sort(productionPlanTable)", function (obj) {
      table.reload("productionPlanTable", {
        initSort: obj,
        where: {
          sort: obj.field,
          order: obj.type
        }
      });
    });

    // 搜索
    form.on("submit(formSubSearchLog)", function (data) {
      data.field.workshopName=''
      data.field.workshopName = deviceRes.find((v) => v.id == data.field.workshopId)?.name;
      insTb.reload({ where: data.field, page: { curr: 1 } }, "data");
    });

    // 重置搜索
    form.on("submit(resets)", (data) => {
      data.field.workshopName=''

      insTb.reload({ where: admin.resetSearch(data.field), page: { curr: 1 } }, "data");
    });

    form.render("select");

    $("#addProductionPlanBtn").click(function () {
      addProductionPlan();
    });
    $("#addBtn").click(function () {
      openForm("add");
    });
    $("#xxxxx").click(function () {
      admin.formOpen({
        area: ["85%", "90%"],
        title: "生产计划排产",
        path: "components/component/checkSkuForm.html",
        success: function () {
          // parentData.url = "enterprise/product/admin/productDetailWMS/list";
          // parentData.where={
          //   skuName:'zhoudada-name'
          // }
          parentData.isPage = true;
        }
      });
    });
    function openForm(eventName, id) {
      admin.formOpen({
        type: 1,
        area: ["95%", "85%"],
        title: "添加生产计划",
        path: "components/productionPlan/productionPlanForm.html",
        success: function () {
          parentData.eventName = eventName;
          parentData.id = id;
        }
      });
    }
    // 显示编辑弹窗
    function productionPlanModel(data) {
      admin.open({
        type: 1,
        area: ["84%", "830px"],
        title: "物料生产计划排产",
        content: $("#productionPlanForm").html(),
        success: function () {
          let productionPlanId = data.id;
          let customerSkuCode = data.customerSkuCode;
          // 顶部详情数据

          var detailProductionPlanTable = table.render({
            elem: "#detailProductionPlanTable",
            data: [data],
            cellMinWidth: 100,
            cols: [
              [
                {
                  field: "code",
                  align: "center",
                  title: "计划编号",
                  width: 150
                },
                // { field: "planSourceDesc", align: "center", title: "计划订单类型" },
                { field: "bookCode", align: "center", title: "基准书编号" },
                {
                  field: "customerSkuCode",
                  align: "center",
                  title: "生产物料"
                },
                {
                  field: "customerSkuSpec",
                  align: "center",
                  title: "物料规格"
                },
                {
                  field: "productTypeName",
                  align: "center",
                  title: "所属物料系列"
                },
                {
                  field: "productionQuantity",
                  align: "center",
                  title: "生产数量"
                },
                {
                  field: "productionPlanHaveQuantity",
                  title: "已排产数量",
                  align: "center"
                },
                {
                  field: "productionPlanQuantity",
                  title: "本次生产数量",
                  align: "center",
                  templet: admin.setTableInput("productionPlanQuantity")
                },
                // { field: "yeild", title: "合格率", align: "center" },
                // { field: "customerName", align: "center", title: "客户信息" },
                {
                  field: "shipmentTime",
                  align: "center",
                  title: "交货时间",
                  width: 160
                },
                { field: "statusDesc", align: "center", title: "状态" },
                {
                  field: "createTime",
                  align: "center",
                  title: "创建时间",
                  width: 160
                }
              ]
            ]
          });
          admin.tableInputChange("detailProductionPlanTable");
          // 节点数据
          let processNodsData = [];
          let nodeIndex = 0;
          // let processList = [];
          // 如果有缓存
          let saveProcessData = config.getTempData("saveProcessData");
          if (saveProcessData != undefined && saveProcessData != "") {
            // 如果有缓存则拿缓存的数据
            saveProcessData.forEach((item, index) => {
              if (item.productionPlanId == productionPlanId) {
                item.title = "工序" + toChinesNum(processNodsData.length + 1);
                processNodsData.push(item);
              }
            });
            if (processNodsData.length > 0) {
              addTemplate();
            }
          } else if (data.planNature == "process") {
            console.log("data1", data);
            // 如果计划有生产工序则隐藏添加按钮
            $("#addProcessNods").hide();
            $(".layui-tab-close").hide();
            getProcessOutputAndYield(data.processId, data.processName);
          } else {
            // 如果计划没有生产工序查当前基准书所有工序
            admin.req("enterprise/echnologyParam/admin/echnologyParam/getEchonlogyInfoBy/" + data.bookId, {}, async function (res) {
              if (res.code == 200) {
                layer.closeAll("loading");
                if (res.code == 200) {
                  if (res.data.length > 0) {
                    for (const item of res.data) {
                      await getProcessOutputAndYield(item.id, item.name, item.salaryQuota, item);
                    }
                    //   res.data.forEach((item, index) => {
                    //     getProcessOutputAndYield(item.id, item.name, item.salaryQuota);
                    // });
                  } else {
                  }
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              }
            });
            // 节点标题
            // laytpl(processNodsTitleTemplate.innerHTML).render([], function (html) {
            //     $("#processNodsTitle").html(html);
            // });
            // 查询计划的排产工序
            // admin.req(
            //   'enterprise/echnologyParam/admin/echnologyParam/list',
            //   {
            //     skuCode: customerSkuCode,
            //   },
            //   function (res) {
            //     layer.closeAll('loading');
            //     if (res.code == 200) {
            //       if (res.data.length > 0) {
            //         res.data.forEach((item, index) => {
            //           getProcessOutputAndYield(item.id, item.name);
            //         });
            //       } else {
            //       }
            //     } else {
            //       layer.msg(res.msg, { icon: 2 });
            //     }
            //   },
            //   'GET',
            // );
          }

          // tab切换改变下标
          element.on("tab(productionPlanBox)", function () {
            nodeIndex = this.getAttribute("lay-id");
            console.log(processNodsData[nodeIndex]);
            table.reload("relevanceMaterialTable" + nodeIndex, {
              data: processNodsData[nodeIndex].skuList
            });
            // 是否计件工资
            initSelectPieceRate();
          });

          // 查询工序已排产数量和平均合格率
          async function getProcessOutputAndYield(processId, nodeNames, salaryQuota, obj) {
            // const res = await admin.reqPro("production/productionPlan/admin/productionPlan/getProcessOutputAndYield", {
            //   processId: processId,
            //   productionPlanId: productionPlanId
            // });
            console.log("dat1a", data);

            // admin.req(
            //   "production/productionPlan/admin/productionPlan/getProcessOutputAndYield",
            //   {
            //     processId: processId,
            //     productionPlanId: productionPlanId
            //   },
            //   async function (res) {
            layer.closeAll("loading");
            // if (res.code == 200) {
            let numIndex = "工序" + toChinesNum(processNodsData.length + 1);
            let planArr = {
              title: nodeNames, //标题
              productionPlanId: productionPlanId, //id
              processId: processId,
              skuCode: customerSkuCode,
              // productionQuantity: res.data.productionQuantity, //已排产数量
              // yield: res.data.yield, //合格率
              pieceRateStatus: "no", //是否计件工资
              pieceRate: "", //工资
              processDeviceList: [],
              materialList: [],
              salaryQuota: salaryQuota //工资定额
            };
            console.log(1111, data);

            if (data.planNature == "process") {
              const res1 = await admin.reqPro("enterprise/echnologyParam/admin/echnologyParam/getEchonlogyBy/" + processId);
              processNodsData.push({ ...res1.data, ...planArr });
              console.log(43232, { ...res1.data });
            } else {
              processNodsData.push({ ...planArr, ...obj });
            }
            console.log("processNodsData", processNodsData);

            // nodeIndex = processNodsData.length - 1;
            nodeIndex = 0;
            addTemplate();
            // } else {
            //   layer.msg(res.msg, { icon: 2 });
            // }
            //   },
            //   "GET"
            // );
          }

          // 添加模板
          function addTemplate() {
            $(".isData").show();
            // 加载节点标题
            templateTitle();
            // 加载节点内容
            templateContent();
          }

          // 节点标题
          function templateTitle() {
            laytpl(processNodsTitleTemplate.innerHTML).render(processNodsData, function (html) {
              console.log(processNodsData);

              $("#processNodsTitle").html(html);
              // 删除tab选项卡
              deleteTemplateTitle();
            });
          }

          // 删除当前节点内容
          function deleteTemplateTitle() {
            $(".layui-tab-close").click(function () {
              let that = $(this);
              layer.confirm(
                "确定要删除当前工序吗？",
                {
                  offset: "65px",
                  skin: "layui-layer-admin"
                },
                function (i) {
                  layer.close(i);
                  // 删除当前DOM
                  that.parents("#processNodsTitle").find("li").eq(nodeIndex).remove();
                  $("#processNodsContent").find(".layui-tab-item").eq(nodeIndex).remove();
                  // 如果有缓存则删除缓存
                  let filterList = [processNodsData[nodeIndex]];
                  let saveProcessData = config.getTempData("saveProcessData");
                  if (saveProcessData != undefined && saveProcessData != "") {
                    filterList.forEach((item) => {
                      let index = saveProcessData.findIndex((ele) => ele.processId == item.processId && ele.productionPlanId == item.productionPlanId);
                      if (index > -1) {
                        saveProcessData.splice(index, 1);
                      }
                    });
                  }
                  // 删除当前页面数据
                  processNodsData.splice(nodeIndex, 1);
                  // 如果当前数据长度为0则隐藏保存工序排产计划
                  if (processNodsData.length == 0) {
                    $(".isData").hide();
                  } else {
                    // processNodsData.forEach((item, index) => {
                    //     item.title = '工序' + toChinesNum(index + 1)
                    // });
                    // 删除tab选项卡则显示前面个tab 同时改变nodeIndex
                    nodeIndex--;
                    // 回调重新执行函数 重新渲染模板
                    addTemplate();
                  }
                  // 重新缓存数据
                  config.putTempData("saveProcessData", saveProcessData);
                }
              );
            });
          }

          function initSelectPieceRate() {
            form.on("select(pieceRateStatus" + nodeIndex + ")", function (d) {
              let elem = d.elem;
              let elemVal = elem[elem.selectedIndex].value;
              let dom = "pieceRateStatus" + nodeIndex;
              // 如果下拉框是当前选项则回显值并改变数组 再判断是否显示计件工资
              console.log(1111);
              if (elem.name === dom) {
                processNodsData[nodeIndex].pieceRateStatus = elemVal;
                let selectDom = "#isPieceRate" + nodeIndex;
                if (elemVal === "yes") {
                  $(selectDom).show();
                  $(selectDom).find("input").attr("lay-verify", "required");
                } else {
                  $(selectDom).find("input").attr("lay-verify", "none");
                  $(selectDom).hide();
                }
              }
            });
            // 排产设备工具条点击事件
            table.on("tool(deviceProductionTable" + nodeIndex + ")", function (obj) {
              console.log(111);
              let rowData = obj.data;
              let list = processNodsData[nodeIndex].processDeviceList;
              if (obj.event === "save") {
                // 保存
                let planProductionQuantity = $(this).parents("td").siblings().find(".planProductionQuantity").val();
                // if (planProductionQuantity == "") {
                //   layer.msg("请输入计划排产数量", { icon: 2 });
                //   return false;
                // }
                list.forEach((item, index) => {
                  if (rowData.deviceCode === item.deviceCode) {
                    list[index].status = "yes";
                    list[index].planProductionQuantity = planProductionQuantity;
                  }
                });
              } else if (obj.event === "del") {
                //删除
                list.forEach((item, index) => {
                  if (rowData.deviceCode === item.deviceCode) {
                    list.splice(index, 1);
                  }
                });
              } else if (obj.event === "edit") {
                //修改
                list.forEach((item, index) => {
                  if (rowData.deviceCode === item.deviceCode) {
                    list[index].status = "no";
                  }
                });
              } else if (obj.event === "detail") {
                // 明细
                getDeviceWorkOrderPageList(rowData);
              }
              // 渲染表格
              table.reload("deviceProductionTable" + nodeIndex, {
                data: list
              });
              console.log(processNodsData, "排产设备数据");
            });

            // 排产物料操作系列
            table.on("tool(relevanceMaterialTable" + nodeIndex + ")", function (obj) {
              let rowData = obj.data;
              // let list = processNodsData[nodeIndex].skuList;
              let list = table.cache["relevanceMaterialTable" + nodeIndex];
              console.log(list, "list");

              if (obj.event === "del") {
                //删除
                // list.forEach((item, index) => {
                //   if (rowData.productDetailId === item.productDetailId) {
                //     list.splice(index, 1);
                //   }
                // });
                let index = $(obj.tr[0]).data("index");
                list.splice(index, 1);
                // table.reload("skuTable", { data: list });
              }
              // 渲染表格
              table.reload("relevanceMaterialTable" + nodeIndex, {
                data: list
              });
            });

            // 计件工资
            $("body").delegate(".pieceRate", "change", function () {
              let reg = /^[1-9]+[0-9]*$/;
              let val = $(this).val();
              let list = processNodsData[nodeIndex];
              if (!reg.test(val)) {
                layer.msg("请输入正确的数字", { icon: 2 });
                $(this).val("");
              } else {
                list.pieceRate = val;
              }
            });

            // 计划排产数量
            $("body").delegate(".planProductionQuantity", "change", function () {
              let id = $(this).attr("deviceId");
              let reg = /^[1-9]+[0-9]*$/;
              let planProductionQuantity = $(this).val();
              let list = processNodsData[nodeIndex].processDeviceList;
              list.forEach((item) => {
                if (item.id === id) {
                  if (!reg.test(planProductionQuantity)) {
                    layer.msg("请输入正确的数字", { icon: 2 });
                    $(this).val("");
                  }
                }
              });
            });
          }

          // 节点内容
          function templateContent() {
            laytpl(processNodsContentTemplate.innerHTML).render(processNodsData, function (html) {
              $("#processNodsContent").html(html);
              // 显示最新的添加项
              $("#processNodsTitle").find("li").removeClass("layui-this").eq(nodeIndex).addClass("layui-this");
              $("#processNodsContent").find(".layui-tab-item").removeClass("layui-show").eq(nodeIndex).addClass("layui-show");
              form.render("select");
              // 选择工序带出默认物料
              let isMaterialList = processNodsData[nodeIndex].materialList;
              if (isMaterialList.length == 0) {
                let processId = processNodsData[nodeIndex].processId;
                admin.reqSync(
                  "production/productionPlan/admin/productionPlan/getProcessMaterialPageList",
                  {
                    processId: processId,
                    skuCode: customerSkuCode
                  },
                  function (res) {
                    if (res.code == 200) {
                      let list = [];
                      res.data.forEach((ele) => {
                        list.push({
                          materialSkuCode: ele.skuCode,
                          processId: processId
                        });
                      });
                      processNodsData[nodeIndex].materialList = list;
                    } else {
                      layer.msg(res.msg, { icon: 2 });
                    }
                  },
                  "GET"
                );
              }
              for (let i = 0; i < processNodsData.length; i++) {
                // 关联物料表格
                table.render({
                  elem: "#relevanceMaterialTable" + i,
                  data: processNodsData[i].materialList,
                  cellMinWidth: 100,
                  page: false,
                  cols: [
                    [
                      { type: "numbers", width: 40, title: "序号" },
                      // { field: "materialSkuCode", title: "物料信息", align: "center", width: 250 },
                      {
                        field: "skuCode",
                        title: "物料编码",
                        align: "center"
                      },
                      {
                        field: "skuName",
                        title: "物料名称",
                        align: "center"
                      },
                      {
                        field: "quantity",
                        title: "需求数量",
                        align: "center",
                        edit: "textarea"
                      },

                      {
                        align: "center",
                        toolbar: "#relevanceMaterialTableBar",
                        title: "操作",
                        width: 80
                      }
                    ]
                  ]
                });
                table.on("edit(relevanceMaterialTable" + i + ")", function (obj) {
                  var value = obj.value; // 得到修改后的值
                  var data = obj.data; // 得到所在行所有键值
                  var field = obj.field; // 得到字段
                  var index = $(obj.tr).data("index");

                  // 更新数据中对应的字段
                  var update = {};
                  update[field] = value;
                  obj.update(update);
                  processNodsData[i].skuList[index][field] = value;
                  // 编辑后续操作，如提交更新请求，以完成真实的数据更新
                  // …

                  // 显示当前行最新数据 - 仅用于示例展示
                  // showData(data);
                });
                // 机台排产表格
                table.render({
                  elem: "#deviceProductionTable" + i,
                  data: processNodsData[i].processDeviceList,
                  cellMinWidth: 100,
                  page: false,
                  cols: [
                    [
                      { type: "numbers", width: 50, title: "序号" },
                      {
                        field: "deviceModel",
                        width: 150,
                        title: "设备型号",
                        align: "center"
                      },
                      {
                        field: "deviceCode",
                        width: 140,
                        title: "设备编码",
                        align: "center"
                      }
                      // { field: "yeild", width: 130, title: "机台平均合格率", align: "center" },
                      // {
                      //   field: "planProductionQuantity",
                      //   title: "计划排产数量",
                      //   align: "center",
                      //   width: 155,
                      //   templet: function (d) {
                      //     if (d.status == "yes") {
                      //       return "<span>" + d.planProductionQuantity + "</span>";
                      //     } else {
                      //       return (
                      //         '<input deviceId="' +
                      //         d.id +
                      //         '" class="layui-input planProductionQuantity" style="height: 28px;" type="text" ' +
                      //         'value="' +
                      //         d.planProductionQuantity +
                      //         '" />'
                      //       );
                      //     }
                      //   }
                      // },
                      // { field: "shipmentTime", title: "计划截止时间", align: "center", width: 160 },
                      // {
                      //   align: "center",
                      //   toolbar: "#deviceProductionTableBar",
                      //   title: "操作",
                      //   width: 240
                      // }
                    ]
                  ]
                });
                // 回显计件工资
                let select = "dd[lay-value=" + processNodsData[i].pieceRateStatus + "]";
                $(`select[name='pieceRateStatus${i}']`).siblings("div.layui-form-select").find("dl").find(select).click();
                $("#isPieceRate" + i)
                  .find("input")
                  .attr("lay-verify", "none");
                $("#isPieceRate" + i).hide();
              }
              // 是否计件工资
              initSelectPieceRate();
            });

            // 添加排产设备
            $(".addDeviceProduction").click(function () {
              let processId = processNodsData[nodeIndex].processId;
              let arrList = [];
              processNodsData[nodeIndex].processDeviceList.forEach((item) => {
                arrList.push(item.deviceCode);
              });
              var selectProcessDeviceByProcessId = admin.open({
                type: 1,
                title: "排产设备",
                area: "75%",
                offset: ["100px", "380px"],
                content: $("#selectProcessDeviceByProcessId").html(),
                success: function () {
                  form.render("select");
                  // 渲染表格
                  var selectProcessDeviceByProcessIdTable = table.render({
                    elem: "#selectProcessDeviceByProcessIdTable",
                    url: config.base + "enterprise/device/admin/device/list",
                    page: true,
                    cellMinWidth: 100,
                    cols: [
                      [
                        { type: "checkbox" },
                        {
                          field: "deviceCode",
                          align: "center",
                          title: "设备编码"
                        },
                        { field: "name", align: "center", title: "设备名称" },
                        {
                          field: "deviceModelName",
                          align: "center",
                          title: "设备型号"
                        },
                        {
                          field: "createTime",
                          align: "center",
                          title: "创建时间"
                        }
                      ]
                    ],
                    done: function (res, curr, count) {
                      // 如果选择过的checkbox 则通过code标识判断 禁用下拉框
                      let allCheck = true;
                      for (let item in res.data) {
                        if (arrList.indexOf(res.data[item].deviceCode) !== -1) {
                          allCheck = false;
                        }
                        break;
                      }
                      if (!allCheck) {
                        $(".layui-table-header")
                          .find("input[name = 'layTableCheckbox'][lay-filter='layTableAllChoose']")
                          .each(function () {
                            $(this).attr("disabled", "disabled").next().removeClass("layui-form-checked");
                            form.render("checkbox");
                          });
                      }
                      let i = 0;
                      $(".layui-table-body.layui-table-main")
                        .find("input[name='layTableCheckbox']")
                        .each(function () {
                          if (arrList.indexOf(res.data[i].deviceCode) != -1) {
                            $(this).attr("disabled", "disabled").removeAttr("checked");
                            $(this).parents("tr").addClass("disabledBg");
                            form.render("checkbox");
                            // $(this).siblings(".layui-form-checkbox").css("opacity", "0");
                          }
                          i++;
                        });
                      i = 0;
                      $(".layui-table-fixed.layui-table-fixed-l")
                        .find(".layui-table-body")
                        .find("input[name='layTableCheckbox']")
                        .each(function () {
                          if (arrList.indexOf(res.data[i].deviceCode) != -1) {
                            $(this).attr("disabled", "disabled").removeAttr("checked");
                            $(this).parents("tr").addClass("disabledBg");
                            form.render("checkbox");
                            // $(this).siblings(".layui-form-checkbox").css("opacity", "0");
                          }
                          i++;
                        });
                    }
                  });

                  // 搜索
                  form.on("submit(selectProcessFormSubSearchLog)", function (data) {
                    selectProcessDeviceByProcessIdTable.reload(
                      {
                        where: data.field,
                        page: { curr: 1 }
                      },
                      "data"
                    );
                  });

                  // 确认选择
                  $("#selectProcessDeviceByProcessIdClose").click(function () {
                    let checkStatus = table.checkStatus("selectProcessDeviceByProcessIdTable"); //test即为基础参数id对应的值
                    let dataS = checkStatus.data;
                    if (checkStatus.data.length == 0) {
                      layer.msg("请选择设备", { icon: 2, time: 1000 });
                    } else {
                      let list = processNodsData[nodeIndex].processDeviceList;
                      // let filterList = list.filter((item) => {
                      //     return item.deviceCode == dataS[0].deviceCode
                      // });
                      // if (filterList.length > 0) {
                      //     layer.msg('当前选择的设备已存在', {icon: 2});
                      //     return false;
                      // }
                      dataS.forEach((item) => {
                        list.push({
                          processId: processId,
                          id: item.id,
                          deviceCode: item.deviceCode,
                          deviceModel: item.deviceModel,
                          planProductionQuantity: "", //计划排产数量
                          yeild: item.yeild, //台机评价合格率
                          shipmentTime: data.shipmentTime, //当前计划截止时间从data数据带出
                          status: "no"
                        });
                      });
                      layer.close(selectProcessDeviceByProcessId);

                      // 渲染表格
                      table.reload("deviceProductionTable" + nodeIndex, {
                        data: list
                      });
                      $(".open-details-box").scrollTop($(".open-details-box").height());
                    }
                  });
                }
              });
            });

            // 添加关联物料
            $(".addRelevanceMaterial").click(function () {
              let index = $(".layui-tab-title .layui-this").attr("lay-id");
              let list = table.cache["relevanceMaterialTable" + index];
              console.log(list);
              console.log(processNodsData[index].skuList);

              admin.formOpen({
                title: "配置关联物料",
                area: "90%",
                offset: "50px",
                path: "components/purchase/skuTableForm.html",
                success: function () {
                  parentData.notInListIds = list.map((v) => v.productDetailId).join(",");
                },
                end: function () {
                  console.log(index);
                  if (childData.list && childData.list.length > 0) {
                    list = [...list, ...childData.list];
                    processNodsData[index].skuList = list;
                    table.reload("relevanceMaterialTable" + index, {
                      data: list
                    });
                  }
                  // let checkStatus = table.checkStatus("selectProcessMaterialPageListTable"); //test即为基础参数id对应的值
                  // let dataS = checkStatus.data;
                  // if (checkStatus.data.length == 0) {
                  //   layer.msg("请选择物料", { icon: 2, time: 1000 });
                  // } else {
                  //   let list = processNodsData[nodeIndex].materialList;
                  //   let filterList = list.filter((item) => {
                  //     return item.materialSkuCode == dataS[0].skuCode;
                  //   });
                  //   if (filterList.length > 0) {
                  //     layer.msg("当前选择的物料已存在", { icon: 2 });
                  //     return false;
                  //   }
                  //  let len = $(this).parents('.template-box').data('id');
                  //   list.push({
                  //     materialSkuCode: dataS[0].skuCode,
                  //     processId: processId
                  //   });
                  //   // 渲染表格
                  //   table.reload("relevanceMaterialTable" + nodeIndex, {
                  //     data: list
                  //   });
                  //   layer.close(selectProcessMaterialPageList);
                  // }
                }
              });

              //   let processId = processNodsData[nodeIndex].processId;
              //   var selectProcessMaterialPageList = admin.open({
              //     type: 1,
              //     title: "排产物料",
              //     area: "82%",
              //     offset: ["100px", "280px"],
              //     content: $("#selectProcessMaterialPageList").html(),
              //     success: function () {
              //       //物料类别
              //       admin.initDataSelectTree(true, "enterprise/product/admin/productType/getTreeData", null, "selectProductType", null, "物料类别", "productTypeId", null);
              //       form.render("select");
              //       // 渲染表格
              //       var selectProcessDeviceByProcessIdTable = table.render({
              //         elem: "#selectProcessMaterialPageListTable",
              //         url: config.base + "enterprise/product/admin/productDetail/list",
              //         page: true,
              //         cellMinWidth: 100,
              //         cols: [
              //           [
              //             { type: "radio" },
              //             { field: "skuCode", title: "物料编码", align: "center" },
              //             { field: "skuName", title: "物料名称", align: "center" },
              //             { field: "skuSpec", title: "物料规格", align: "center" },
              //             { field: "productTypeName", title: "物料类型", align: "center" },
              //             { field: "unitName", title: "物料单位", align: "center" },
              //             { field: "quantityStock", title: "库存数量", align: "center" },
              //             { field: "createTime", title: "创建时间", align: "center" }
              //           ]
              //         ]
              //       });

              //       // 获取物料类型
              //       admin.reqSync(
              //         "enterprise/product/admin/productType/getProductTypeVOAll",
              //         {},
              //         function (res) {
              //           if (res.code == 200) {
              //             $.each(res.data, function (index, item) {
              //               $("#productTypeId").append(new Option(item.name, item.id));
              //             });
              //           } else {
              //             layer.msg(res.msg, { icon: 2 });
              //           }
              //         },
              //         "GET"
              //       );

              //       // 获取物料分类
              //       admin.reqSync(
              //         "enterprise/product/admin/productCategory/getAll",
              //         {},
              //         function (res) {
              //           if (res.code == 200) {
              //             $.each(res.data, function (index, item) {
              //               $("#productCategoryId").append(new Option(item.name, item.id));
              //             });
              //           } else {
              //             layer.msg(res.msg, { icon: 2 });
              //           }
              //         },
              //         "GET"
              //       );

              //       form.render("select");

              //       // 搜索
              //       form.on("submit(selectProcessMaterialPageListFormSubSearchLog)", function (data) {
              //         selectProcessDeviceByProcessIdTable.reload(
              //           {
              //             where: data.field,
              //             page: { curr: 1 }
              //           },
              //           "data"
              //         );
              //       });

              //       // 确认选择
              //       $("#selectProcessMaterialPageListClose").click(function () {
              //         let checkStatus = table.checkStatus("selectProcessMaterialPageListTable"); //test即为基础参数id对应的值
              //         let dataS = checkStatus.data;
              //         if (checkStatus.data.length == 0) {
              //           layer.msg("请选择物料", { icon: 2, time: 1000 });
              //         } else {
              //           let list = processNodsData[nodeIndex].materialList;
              //           let filterList = list.filter((item) => {
              //             return item.materialSkuCode == dataS[0].skuCode;
              //           });
              //           if (filterList.length > 0) {
              //             layer.msg("当前选择的物料已存在", { icon: 2 });
              //             return false;
              //           }
              //           // let len = $(this).parents('.template-box').data('id');
              //           list.push({
              //             materialSkuCode: dataS[0].skuCode,
              //             processId: processId
              //           });
              //           // 渲染表格
              //           table.reload("relevanceMaterialTable" + nodeIndex, {
              //             data: list
              //           });
              //           layer.close(selectProcessMaterialPageList);
              //         }
              //       });
              //     }
              //   });
            });
          }

          // 缓存当前数据
          $("#saveProcessPlan").click(function () {
            let saveProcessData = config.getTempData("saveProcessData");
            let tempList = [],
              currentData = processNodsData[nodeIndex];
            let filterList = [currentData];
            if (currentData.processDeviceList.length == 0) {
              layer.msg("请添加排产设备", { icon: 2 });
              return false;
            }
            if (currentData.materialList.length == 0) {
              layer.msg("请添加排产物料", { icon: 2 });
              return false;
            }
            if (saveProcessData != undefined && saveProcessData != "") {
              // 筛选是否有相同ID的数据
              filterList.forEach((item) => {
                let index = saveProcessData.findIndex((ele) => ele.processId == item.processId && ele.productionPlanId == item.productionPlanId);
                if (index > -1) {
                  saveProcessData[index] = item;
                } else {
                  saveProcessData.push(item);
                }
              });
            } else {
              tempList.push(currentData);
              saveProcessData = tempList;
            }
            config.putTempData("saveProcessData", saveProcessData);
            layer.msg("缓存成功", { icon: 1 });
          });

          // 提交数据
          form.on("submit(productionPlanFormSubmit)", function (d) {
            let deviceFilter = [],
              flag = false;
            if (processNodsData.length == 0) {
              layer.msg("请添加工序", { icon: 2 });
              return false;
            }
            // 循环判断不能提交为空的数据
            console.log("processNodsData11", processNodsData);

            processNodsData.forEach((item, index) => {
              // console.log(table.cache["relevanceMaterialTable" + index]);

              // item.materialList = item.skuList;
              item.materialList = table.cache["relevanceMaterialTable" + index];
              item.skuList = table.cache["relevanceMaterialTable" + index];
              if (item.processDeviceList.length == 0) {
                layer.msg(`${item.title}排产设备不能为空`, { icon: 2 });
                flag = true;
                return false;
              }
              if (item.materialList.length == 0) {
                layer.msg(`${item.title}排产物料不能为空`, { icon: 2 });
                flag = true;
                return false;
              }
              deviceFilter = item.processDeviceList.filter((item) => {
                return item.status == "yes";
              });
              // if (deviceFilter.length == 0) {
              //   layer.msg(`请保存${item.title}的排产设备`, { icon: 2 });
              //   flag = true;
              //   return false;
              // }
            });
            // 控制不能提交为空的数据
            if (flag) {
              return false;
            }
            let productionList = [];
            processNodsData.forEach((item) => {
              // 筛选出有保存过的排产设备
              // let deviceFilter = item.processDeviceList.filter((item) => {
              //   return item.status == "yes";
              // });
              let list = [];
              item.processDeviceList.forEach((ele) => {
                list.push({
                  deviceCode: ele.deviceCode,
                  deviceModel: ele.deviceModel,
                  planProductionQuantity: ele.planProductionQuantity,
                  outputQuantity: ele.outputQuantity,
                  processId: ele.processId
                });
              });
              // 提交的数组
              productionList.push({
                productionPlanId: item.productionPlanId,
                processId: item.processId,
                processName: item.title,
                pieceRateStatus: item.pieceRateStatus,
                pieceRate: item.pieceRate,
                skuCode: item.skuCode,
                processDeviceList: list,
                materialList: item.materialList,
                skuList: item.skuList
              });
            });
            layer.load(2);
            let formData = {
              productionPlanId: table.cache["detailProductionPlanTable"][0].id,
              productionPlanQuantity: table.cache["detailProductionPlanTable"][0].productionPlanQuantity,
              productionPlanHaveQuantity: table.cache["detailProductionPlanTable"][0].productionPlanHaveQuantity,
              submitProductionPlanForms: productionList
            };
            console.log(formData);
            console.log(table.cache["detailProductionPlanTable"]);

            // return false;
            // 提交计划
            admin.req(
              "production/productionPlan/admin/productionPlan/submitProductionPlan",
              JSON.stringify(formData),
              function (res) {
                layer.closeAll("loading");
                if (res.code == 200) {
                  // 提交成功清空缓存数据
                  let saveProcessData = config.getTempData("saveProcessData");
                  let saveList = [];
                  if (saveProcessData != undefined && saveProcessData != "") {
                    saveProcessData.forEach((item) => {
                      if (item.productionPlanId != productionPlanId) {
                        saveList.push(item);
                      }
                    });
                  }
                  config.putTempData("saveProcessData", saveList);
                  layer.msg(res.msg, { icon: 1 });
                  table.reload("productionPlanTable");
                  layer.closeAll();
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              "POST",
              true,
              "application/json; charset=utf-8"
            );
            return false;
          });
        }
      });
    }

    // 通过设备明细查询生产开工单列表
    function getDeviceWorkOrderPageList(data) {
      admin.open({
        type: 1,
        area: ["82%", "830px"],
        offset: "65px",
        title: "生产开工单列表",
        content: $("#deviceWorkOrderTemplate").html(),
        success: function () {
          form.render("select");
          var deviceWorkOrderTable = table.render({
            elem: "#deviceWorkOrderTable",
            url: config.base + "production/productionPlan/admin/productionPlan/getDeviceWorkOrderPageList?deviceCode=" + data.deviceCode,
            page: true,
            cellMinWidth: 100,
            cols: [
              [
                { type: "numbers", title: "序号" },
                { field: "code", title: "工单编码", align: "center" },
                { field: "processName", title: "所属工序", align: "center" },
                { field: "planCode", title: "所属生产计划", align: "center" },
                {
                  field: "workOrderQualityDesc",
                  title: "工单性质",
                  align: "center"
                },
                { field: "skuName", title: "物料名称", align: "center" },
                { field: "skuCode", title: "物料编码", align: "center" },
                {
                  field: "productTypeName",
                  title: "所属系列",
                  align: "center"
                },
                {
                  field: "productionQuantity",
                  title: "计划数量",
                  align: "center"
                },
                {
                  field: "outputQuantity",
                  title: "排产数量",
                  align: "center"
                },
                {
                  field: "predictFinishTime",
                  title: "预计完工时间",
                  align: "center"
                },
                { field: "statusDesc", title: "状态", align: "center" },
                { field: "no", title: "排序", align: "center" },
                {
                  align: "center",
                  toolbar: "#deviceWorkOrderTableBar",
                  title: "操作",
                  width: 280
                }
              ]
            ]
          });

          form.on("submit(deviceWorkOrderFormSubSearchLog)", function (data) {
            deviceWorkOrderTable.reload({ where: data.field, page: { curr: 1 } }, "data");
            //return false;
          });
          // 工具条点击事件
          table.on("tool(deviceWorkOrderTable)", function (obj) {
            var data = obj.data;
            if (obj.event === "activate") {
              //激活
              operationWorkOrder(data.id, 0, "确定要激活吗？");
            } else if (obj.event === "pause") {
              // 暂停
              operationWorkOrder(data.id, 1, "确定要暂停吗？");
            } else if (obj.event === "close") {
              // 关闭
              operationWorkOrder(data.id, 2, "确定要关闭吗？");
            } else if (obj.event === "up") {
              // 上移
              moveWorkOrder(data.id, 1);
            } else if (obj.event === "down") {
              // 下移
              moveWorkOrder(data.id, 2);
            } else if (obj.event === "detail") {
              getWorkOrderInfoDialog(data.id, data.processId, data.skuCode);
            }
          });

          // 工单激活、暂停、关闭
          function operationWorkOrder(id, type, tips) {
            layer.confirm(
              tips,
              {
                offset: "65px",
                skin: "layui-layer-admin"
              },
              function (i) {
                layer.close(i);
                layer.load(2);
                admin.req(
                  "production/productionPlan/admin/productionPlan/operationWorkOrder",
                  {
                    id: id,
                    type: type
                  },
                  function (res) {
                    layer.closeAll("loading");
                    if (res.code == 200) {
                      layer.msg(res.msg, { icon: 1 });
                      table.reload("deviceWorkOrderTable");
                    } else {
                      layer.msg(res.msg, { icon: 2 });
                    }
                  },
                  "PUT"
                );
              }
            );
          }

          // 上移下移
          function moveWorkOrder(id, type) {
            layer.load(2);
            admin.req(
              "production/productionPlan/admin/productionPlan/moveWorkOrder",
              {
                id: id,
                operaType: type
              },
              function (res) {
                layer.closeAll("loading");
                if (res.code == 200) {
                  layer.msg(res.msg, { icon: 1 });
                  table.reload("deviceWorkOrderTable");
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              "PUT"
            );
          }
        }
      });
    }

    // 开工单详情
    function getWorkOrderInfoDialog(id, processId, skuCode) {
      admin.open({
        type: 1,
        area: ["78%", "810px"],
        offset: "65px",
        title: "设备排产工单信息",
        content: $("#getWorkOrderInfoTemplate").html(),
        success: function () {
          let workerInfoData = {};
          // 获取工单详情
          admin.req(
            "production/productionPlan/admin/productionPlan/getWorkOrderInfo",
            {
              id: id,
              processId: processId,
              skuCode: skuCode
            },
            function (res) {
              if (res.code == 200) {
                workerInfoData = res.data;
                form.val("getWorkOrderInfoForm", workerInfoData);
                $("input[name='workOrderCode']").val(workerInfoData.planDetail[0].workOrderCode);
                $("input[name='planCode']").val(workerInfoData.planDetail[0].code);
              } else {
                layer.msg(res.msg, { icon: 2 });
              }
            },
            "GET",
            false
          );

          // 计划明细
          var workInfoPlanDetailTable = table.render({
            elem: "#workInfoPlanDetailTable",
            data: workerInfoData.planDetail,
            cellMinWidth: 120,
            cols: [
              [
                {
                  field: "productTypeName",
                  title: "物料类型",
                  align: "center"
                },
                {
                  field: "customerSkuCode",
                  title: "客户SKU料号",
                  align: "center"
                },
                {
                  field: "customerSkuName",
                  title: "客户SKU名称",
                  align: "center"
                },
                {
                  field: "customerSkuSpec",
                  title: "客户规格码",
                  align: "center"
                },
                { field: "unitName", title: "单位", align: "center" },
                {
                  field: "demandQuantity",
                  title: "需求数量",
                  align: "center"
                },
                {
                  field: "outputQuantity",
                  title: "排产数量",
                  align: "center"
                },
                {
                  field: "workstationQuantity",
                  title: "排产工站数",
                  align: "center"
                },
                // { field: "customerName", title: "客户信息", align: "center" },
                { field: "statusDesc", title: "状态", align: "center" }
              ]
            ]
          });

          // 工单明细
          var workInfoWorkOrderDetailTable = table.render({
            elem: "#workInfoWorkOrderDetailTable",
            data: workerInfoData.workOrderDetail,
            cellMinWidth: 120,
            cols: [
              [
                { field: "deviceCode", title: "设备编码", align: "center" },
                { field: "deviceModel", title: "设备型号", align: "center" },
                {
                  field: "deviceYield",
                  title: "机台平均合格率",
                  align: "center"
                },
                {
                  field: "outputQuantity",
                  title: "排产数量",
                  align: "center"
                },
                {
                  field: "productionQuantity",
                  title: "计划生产数",
                  align: "center"
                },
                {
                  field: "prepositionTime",
                  title: "前置工单结束时间",
                  align: "center"
                },
                {
                  field: "workOrderQuantity",
                  title: "前置工单数",
                  align: "center"
                },
                {
                  field: "predictStartTime",
                  title: "预计开工时间",
                  align: "center"
                },
                {
                  field: "predictFinishTime",
                  title: "预计完工时间",
                  align: "center"
                }
              ]
            ]
          });

          // 关联物料明细
          var workInfoMaterialDetailTable = table.render({
            elem: "#workInfoMaterialDetailTable",
            data: workerInfoData.materialDetail,
            cellMinWidth: 120,
            cols: [
              [
                { type: "numbers", width: 50, title: "序号" },
                {
                  field: "materialSkuCode",
                  title: "物料编号",
                  align: "center"
                },
                {
                  field: "materialSkuName",
                  title: "物料名称",
                  align: "center"
                },
                {
                  field: "materialSkuSpec",
                  title: "物料规格码",
                  align: "center"
                },
                { field: "unitName", title: "计量单位", align: "center" },
                {
                  field: "fixationDosage",
                  title: "是否固定用量",
                  align: "center"
                },
                { field: "dosage", title: "用量", align: "center" }
              ]
            ]
          });
        }
      });
    }

    //排产记录
    function productionPlanRecordList(data) {
      console.info(data, 9999);
      admin.open({
        type: 1,
        area: ["82%", "80%"],
        title: "排产记录列表",
        content: $("#productionPlanRecordList").html(),
        success: function () {
          table.render({
            elem: "#productionRecordTable",
            url: config.base + "production/productionRecord/admin/productionRecord/list?productionPlanId=" + data.id,
            page: true,
            cellMinWidth: 100,
            cols: [
              [
                { type: "numbers", title: "序号" },
                {
                  field: "productionPlanRecordCode",
                  title: "制造令编号",
                  align: "center",
                  width: 160
                },
                {
                  field: "code",
                  title: "所属计划",
                  align: "center",
                  width: 160
                },
                {
                  field: "planTypeName",
                  title: "生产计划类型",
                  align: "center"
                },
                // { field: "orderTypeDesc", title: "计划订单类型", align: "center" },
                {
                  field: "productTypeName",
                  title: "物料类别",
                  align: "center"
                },
                {
                  field: "customerSkuCode",
                  title: "物料编码",
                  align: "center"
                },
                {
                  field: "customerSkuSpec",
                  title: "物料规格",
                  align: "center"
                },
                {
                  field: "productionQuantity",
                  title: "计划生产数量",
                  align: "center"
                },
                // { field: "productionPlanHaveQuantity", title: "已排产数量", align: "center" },
                {
                  field: "productionPlanQuantity",
                  title: "本次排产数量",
                  align: "center"
                },

                {
                  field: "shipmentTime",
                  title: "交货时间",
                  align: "center",
                  width: 160
                },
                { field: "statusDesc", title: "状态", align: "center" },
                { field: "createTime", title: "创建时间", align: "center" },
                {
                  align: "center",
                  toolbar: "#productionPlanRecordTableBar",
                  title: "操作",
                  fixed: "right"
                }
              ]
            ],
            done: function (res, curr, count) {}
          });

          // 工具条点击事件
          table.on("tool(productionRecordTable)", function (obj) {
            var data = obj.data;
            if (obj.event === "checkPlan") {
              //详情
              // checkProductionPlanDetail(data);
              admin.formOpen({
                area: ["85%", "90%"],
                title: "生产计划排产",
                path: "components/productionPlan/productionPlanningForm.html",
                success: function () {
                  parentData.eventName = "detail";
                  // parentData.id = data.id;
                  parentData.data = { ...data };
                  console.log(data, 9999);
                }
              });
            }
          });
        }
      });
    }

    // 查询排产计划明细
    function checkProductionPlanDetail(data) {
      console.info(data, 9090);
      admin.open({
        type: 1,
        area: ["82%", "80%"],
        offset: ["65px"],
        title: "物料生产计划排产明细",
        content: $("#checkProductionPlanTemplate").html(),
        success: async function () {
          let productionPlanId = data.productionPlanId;
          let productionPlanRecordId = data.id;
          let customerSkuCode = data.customerSkuCode;
          // await admin.reqPro("enterprise/echnologyParam/admin/echnologyParam/list", {
          //   skuCode: customerSkuCode
          // });
          // 顶部详情数据
          var checkProductionPlanTable = table.render({
            elem: "#checkProductionPlanTable",
            data: [data],
            cellMinWidth: 100,
            cols: [
              [
                { field: "code", align: "center", title: "计划编号" },
                // { field: "orderTypeDesc", align: "center", title: "计划订单类型" },
                {
                  field: "customerSkuCode",
                  align: "center",
                  title: "生产物料"
                },
                {
                  field: "customerSkuSpec",
                  align: "center",
                  title: "物料规格"
                },
                {
                  field: "productTypeName",
                  align: "center",
                  title: "所属物料系列"
                },
                {
                  field: "productionQuantity",
                  align: "center",
                  title: "计划生产数量"
                },
                {
                  field: "productionPlanQuantity",
                  title: "本次排产数量",
                  align: "center"
                },

                // { field: "customerName", align: "center", title: "客户信息" },
                {
                  field: "shipmentTime",
                  align: "center",
                  title: "交货时间",
                  width: 160
                },
                { field: "statusDesc", align: "center", title: "状态" },
                {
                  field: "createTime",
                  align: "center",
                  title: "创建时间",
                  width: 160
                }
              ]
            ]
          });
          console.log(data, "234");

          // 查询计划的排产工序
          admin.req(
            // "enterprise/echnologyParam/admin/echnologyParam/list",
            "production/productionRecord/admin/productionRecord/detail",
            // "enterprise/echnologyParam/admin/echnologyParam/getEchonlogyInfoBy/" + data.bookId,
            {
              // skuCode: customerSkuCode
              type: data.planNature,
              productionPlanRecordId: data.id,
              processId: data.processId,
              bookId: data.bookId
            },
            function (res) {
              layer.closeAll("loading");
              if (res.code == 200) {
                processList = res.data;
                if (processList.length > 0) {
                  let checkProcessNodsData = [];
                  processList.forEach((item, index) => {
                    checkProcessNodsData.push({
                      title: item.name,
                      id: item.id
                    });
                  });
                  $("#checkProductionPlan").show();
                  // 渲染工序
                  laytpl(checkProcessNodsTitleTemplate.innerHTML).render(checkProcessNodsData, function (html) {
                    $("#checkProcessNodsTitle").html(html);
                    $("#checkProcessNodsTitle").find("li").removeClass("layui-this").eq(0).addClass("layui-this");
                  });
                  getProcessOutputAndYield(processList[0].id);
                  // getProcessDeviceByProcessId(processList[0].id);
                  table.reload("checkDeviceProductionTable", {
                    data: processList[0].productionProcessDevices
                  });
                  table.reload("checkRelevanceMaterialTable", {
                    data: processList[0].recordMaterialSkuVos
                  });
                } else {
                  $("#checkProductionPlan").hide();
                }
              } else {
                layer.msg(res.msg, { icon: 2 });
              }
            },
            "GET"
          );

          // 查询工序已排产数量和平均合格率
          function getProcessOutputAndYield(processId) {
            admin.req(
              "production/productionPlan/admin/productionPlan/getProcessOutputAndYield",
              {
                productionPlanId: productionPlanId,
                processId: processId
              },
              function (res) {
                layer.closeAll("loading");
                if (res.code == 200) {
                  $("input[name='checkRate']").val(res.data.yield + "%");
                  $("input[name='checkQuantity']").val(res.data.productionQuantity);
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              "GET"
            );
          }

          // 设备表格
          var checkDeviceProductionTable = table.render({
            elem: "#checkDeviceProductionTable",
            data: [],
            cellMinWidth: 120,
            cols: [
              [
                { type: "numbers", width: 50, title: "序号" },
                { field: "deviceModel", title: "设备型号", align: "center" },
                { field: "deviceCode", title: "设备编码", align: "center" },
                { field: "yeild", title: "机台平均合格率", align: "center" },
                // { field: "planProductionQuantity", title: "计划排产数量", align: "center" },
                {
                  field: "outputTime",
                  title: "当前计划截止时间",
                  align: "center"
                }
              ]
            ]
          });
          // 关联物料表格
          var checkRelevanceMaterialTable = table.render({
            elem: "#checkRelevanceMaterialTable",
            data: [],
            cellMinWidth: 120,
            cols: [
              [
                { type: "numbers", width: 50, title: "序号" },
                { field: "skuCode", title: "物料编号", align: "center" },
                { field: "skuName", title: "物料名称", align: "center" },
                { field: "quantity", title: "需求数量", align: "center" }
              ]
            ]
          });
          // 查询计划排产明细工序的设备
          function getProcessDeviceByProcessId(processId) {
            admin.req(
              "production/productionPlan/admin/productionPlan/getProcessDeviceByProcessId",
              {
                productionPlanId: productionPlanId,
                productionPlanRecordId: productionPlanRecordId,
                processId: processId
              },
              function (res) {
                layer.closeAll("loading");
                if (res.code == 200) {
                  console.log(res.data, 9999);

                  table.reload("checkDeviceProductionTable", {
                    data: res.data
                  });
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              "GET"
            );
          }

          // tab切换改变下标
          element.on("tab(checkProductionPlan)", function (v) {
            console.log(333333);

            let id = this.getAttribute("process-id");

            layer.load(2);
            getProcessOutputAndYield(id);
            // getProcessDeviceByProcessId(id);
            console.log(v, 9999);

            table.reload("checkDeviceProductionTable", {
              data: processList[v.index].productionProcessDevices
            });
            table.reload("checkRelevanceMaterialTable", {
              data: processList[v.index].recordMaterialSkuVos
            });
          });
        }
      });
    }

    // 数字转汉字
    function toChinesNum(num) {
      let changeNum = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
      let unit = ["", "十", "百", "千", "万"];
      num = parseInt(num);
      let getWan = (temp) => {
        let strArr = temp.toString().split("").reverse();
        let newNum = "";
        let newArr = [];
        strArr.forEach((item, index) => {
          newArr.unshift(item === "0" ? changeNum[item] : changeNum[item] + unit[index]);
        });
        let numArr = [];
        newArr.forEach((m, n) => {
          if (m !== "零") numArr.push(n);
        });
        if (newArr.length > 1) {
          newArr.forEach((m, n) => {
            if (newArr[newArr.length - 1] === "零") {
              if (n <= numArr[numArr.length - 1]) {
                newNum += m;
              }
            } else {
              newNum += m;
            }
          });
        } else {
          newNum = newArr[0];
        }

        return newNum;
      };
      let overWan = Math.floor(num / 10000);
      let noWan = num % 10000;
      if (noWan.toString().length < 4) {
        noWan = "0" + noWan;
      }
      return overWan ? getWan(overWan) + "万" + getWan(noWan) : getWan(num);
    }

    // addProductionPlan
    // 添加生产计划弹窗
    function addProductionPlan(data, _type) {
      admin.open({
        type: 1,
        area: ["80%", "90%"],
        //   offset: ['100px', '400px'],
        title: data ? "编辑生产计划" : "添加生产计划",
        content: $("#addProductionPlanForm").html(),
        success: async function () {
          //计划来源
          admin.getDictList("planSource", "production_plan_source", data ? data.planSource : null, "计划来源");
          //订单类型
          admin.getDictList("orderType", "production_plan_order_type", data ? data.orderType : null, "订单类型");
          //计划性质
          admin.getDictList("planNature", "production_plan_nature", data ? data.planNature : null, "计划性质");

          let addProductionPlanData = "";
          if (data) {
            admin.reqSync(
              "production/productionPlan/admin/productionPlan/getProductionPlanDetails",
              { id: data.id },
              (res) => {
                addProductionPlanData = JSON.parse(JSON.stringify(res.data));
                planSourceFun(res.data.planSource);
                if (res.data.planSource === "order") {
                  // getProcessIdData(res.data.productTypeId);
                  // customerSkuCodeGetDataFun(res.data.orderId);
                } else if (res.data.planSource === "temporary" || res.data.planSource === "research") {
                  // getProcessIdData(res.data.productTypeId);
                } else {
                  // getProcessIdData(res.data.productTypeId);
                }
                if (res.data.accessory) {
                  $("#accessoryPath").html('<a href="' + res.data.accessory + '" target="_blank">' + res.data.accessory + "</a>");
                }
                planNatureFun(res.data.planNature);
              },
              "get"
            );
            if (_type == "confirmSubmission") {
              // 确认提交的时候 隐藏暂时保存按钮
              $('form[lay-filter="addProductionPlanForm"] button[lay-filter="addProductionPlanFormSubmit"]').hide();
            }
            $("#creatorNameBox").show({ duration: 300 });
            $("#phoneBox").show({ duration: 300 });
            $("#auditPersonBox").hide();
            $('form[lay-filter="addProductionPlanForm"] select[name="planSource"]').attr("disabled", "");
          } else {
            // 创建的时候 隐藏计划创建人  隐藏创建人电话  隐藏创建人电话  隐藏计划审核人
            $("#creatorNameBox").hide({ duration: 300 });
            $("#phoneBox").hide({ duration: 300 });
            $("#auditPersonBox").hide({ duration: 300 });
            $('form[lay-filter="addProductionPlanForm"] input[name="creatorName"]').val("");
            $('form[lay-filter="addProductionPlanForm"] input[name="phone"]').val("");
            $('form[lay-filter="addProductionPlanForm"] input[name="auditPerson"]').val("");

            // 计划来源下拉方法（默认值）
            planSourceFun($("form[lay-filter='addProductionPlanForm'] select[name='planSource'] option:selected").val());

            // 所属合同下拉方法（默认值）
            // signOrNotFun($("form[lay-filter='addProductionPlanForm'] select[name='signOrNot'] option:selected").val());

            // 计划性质下拉方法（默认值）
            planNatureFun($("form[lay-filter='addProductionPlanForm'] select[name='planNature'] option:selected").val());
          }

          // 计划产出时间
          laydate.render({
            elem: "#plannedOutputTime",
            type: "datetime"
          });

          // 交货时间
          laydate.render({
            elem: "#addProductionPlanDeliveryTime",
            type: "datetime"
          });

          // 订单编号
          admin.reqSync(
            "enterprise/sell/admin/order/getOrderPageList",
            {
              page: 1,
              limit: 9999
            },
            function (res) {
              if (res.code == 200) {
                loadSelectHtml(res.data, "请选择订单编号", "orderId", "addProductionPlanForm", 4);
              }
            },
            "GET"
          );

          // 所属合同
          /*admin.reqSync('enterprise/sell/admin/customerContract/list', {
                          page: 1,
                          limit: 9999
                      }, function (res) {
                          if (res.code == 200) {
                              loadSelectHtml(res.data, '请选择所属合同', 'contractId', 'addProductionPlanForm', 1)
                          }
                      }, 'GET');*/

          // 物料类型接口
          admin.reqSync(
            "enterprise/product/admin/productType/list",
            { page: 1, limit: 9999 },
            function (res) {
              if (res.code == 200) {
                loadSelectHtml(res.data, "请选择物料类型", "productTypeId", "addProductionPlanForm", 1);
              }
            },
            "GET"
          );

          // 计划分类
          // admin.initDataSelectTree(
          //   true,
          //   "production/productionPlan/admin/productionCategory/getTreeData",
          //   null,
          //   "selectPlanClassify",
          //   data ? data.planClassifyId : null,
          //   "计划分类",
          //   "planClassifyId",
          //   null
          // );

          // 计划类型
          admin.reqSync(
            "production/productionPlan/admin/productionType/list",
            {
              businessProperty: 1,
              page: 1,
              limit: 9999
            },
            function (res) {
              if (res.code == 200) {
                loadSelectHtml(res.data, "请选择计划类型", "planTypeId", "addProductionPlanForm", 1);
              }
            },
            "GET"
          );

          // 物料编号数据请求
          function customerSkuCodeFun(_data) {
            if (_data && _data != "") {
              $("form[lay-filter='addProductionPlanForm'] input[name='customerSkuCode']").val($(_data.elem).find("option:selected").attr("skuCode"));
              $("form[lay-filter='addProductionPlanForm'] input[name='customerSkuName']").val($(_data.elem).find("option:selected").attr("skuName"));
              $("form[lay-filter='addProductionPlanForm'] input[name='customerSkuSpec']").val($(_data.elem).find("option:selected").attr("skuSpec"));
              $("form[lay-filter='addProductionPlanForm'] input[name='residueQuantity']").val($(_data.elem).find("option:selected").attr("residueQuantity"));
              $("form[lay-filter='addProductionPlanForm'] input[name='demandQuantity']").val($(_data.elem).find("option:selected").attr("quantity"));
              $("form[lay-filter='addProductionPlanForm'] input[name='productTypeId']").val($(_data.elem).find("option:selected").attr("productDetailId"));
              $("form[lay-filter='addProductionPlanForm'] input[name='productTypeName']").val($(_data.elem).find("option:selected").attr("productTypeName"));

              //获取物料工序数据
              d($(_data.elem).find("option:selected").attr("productDetailId"));
            } else {
              $("form[lay-filter='addProductionPlanForm'] input[name='customerSkuCode']").val("");
              $("form[lay-filter='addProductionPlanForm'] input[name='customerSkuName']").val("");
              $("form[lay-filter='addProductionPlanForm'] input[name='customerSkuSpec']").val("");
              $("form[lay-filter='addProductionPlanForm'] input[name='demandQuantity']").val("");
              $("form[lay-filter='addProductionPlanForm'] input[name='residueQuantity']").val("");
              $("form[lay-filter='addProductionPlanForm'] input[name='productTypeId']").val("");
              $("form[lay-filter='addProductionPlanForm'] input[name='productTypeName']").val("");
              //  getProcessIdData();
            }
            form.render("select");
          }

          //上传附件
          $("#accessoryBtn").click(uploadFile("accessoryBtn", "accessoryPath", "accessoryFileId"));

          // 计划来源下拉操作
          form.on("select(planSource)", function (data) {
            // 计划来源下拉调用方法
            planSourceFun(data.value);
          });

          //物料类型
          form.on("select(addProductionPlanFormProductTypeId)", function (data) {
            // 调用 请求工序的数据 方法
            //  getProcessIdData(data.value);

            if (data.value && data.value != "") {
              $("form[lay-filter='addProductionPlanForm'] input[name='productTypeName']").val(data.elem[data.elem.selectedIndex].text);
            } else {
              $("form[lay-filter='addProductionPlanForm'] input[name='productTypeName']").val("");
            }
          });

          // 是否已签约下拉操作
          // form.on('select(signOrNot)', function (data) {
          //     signOrNotFun(data.value)
          // });

          form.on("select(planNature)", function (data) {
            planNatureFun(data.value);
          });

          // 物料编号选择事件
          form.on("select(customerSkuCode)", function (data) {
            customerSkuCodeFun(data);
          });

          // 订单编号
          form.on("select(orderId)", function (data) {
            customerSkuCodeGetDataFun(data.value);
            orderIdFun(data);
          });

          // 计划来源下拉方法
          function planSourceFun(_data) {
            // 物料编号请求数据
            customerSkuCodeGetDataFun(_data);
            orderIdFun();
            customerSkuCodeFun();

            if (_data == "temporary" || _data == "") {
              $("#orderTypeBox").show({ duration: 300 });
              $("#orderIdBox").hide({ duration: 300 });
              $("#orderCreatorNameBox").hide({ duration: 300 });
              $("#residueQuantityBox").hide({ duration: 300 });
              $("#orderRemarkBox").hide({ duration: 300 });
              $("#signOrNotBox").hide({ duration: 300 });
              $("#contractIdBox").hide({ duration: 300 });
              $('#contractIdBox input[name="contractId"]').val("");
              $('#signOrNotBox input[name="signOrNot"]').val("");
              $("#orderIdBox select[name='orderId']").val("");
              $("#orderTypeBox select[name='orderType']").val("");
              $("#orderCreatorNameBox select[name='orderCreatorName']").val("");
              // 交货时间
              $("#addProductionPlanDeliveryTime").val("");
              $("#addProductionPlanDeliveryTime").removeAttr("readonly");
              $("#addProductionPlanDeliveryTime").removeAttr("disabled");
              $("#addProductionPlanDeliveryTime").attr("lay-verify", "required");
              $("#orderIdBox select[name='orderId']").removeAttr("lay-verify");
              $("#orderTypeBox select[name='orderType']").removeAttr("lay-verify");
              $("#orderCreatorNameBox select[name='orderCreatorName']").removeAttr("lay-verify");
              $('form[lay-filter="addProductionPlanForm"] input[name="demandQuantity"]').removeAttr("readonly");
            } else if (_data == "research") {
              $("#orderTypeBox").show({ duration: 300 });
              $("#orderIdBox").hide({ duration: 300 });
              $("#orderCreatorNameBox").hide({ duration: 300 });
              $("#residueQuantityBox").hide({ duration: 300 });
              $("#orderRemarkBox").hide({ duration: 300 });
              $("#signOrNotBox").hide({ duration: 300 });
              $("#contractIdBox").hide({ duration: 300 });
              $('#contractIdBox input[name="contractId"]').val("");
              $('#signOrNotBox input[name="signOrNot"]').val("");
              $("#orderIdBox select[name='orderId']").val("");
              $("#orderTypeBox select[name='orderType']").val("");
              $("#orderCreatorNameBox select[name='orderCreatorName']").val("");
              // 交货时间
              $("#addProductionPlanDeliveryTime").val("");
              $("#addProductionPlanDeliveryTime").removeAttr("readonly");
              $("#addProductionPlanDeliveryTime").removeAttr("disabled");
              $("#addProductionPlanDeliveryTime").attr("lay-verify", "required");
              $("#orderIdBox select[name='orderId']").removeAttr("lay-verify");
              $("#orderTypeBox select[name='orderType']").removeAttr("lay-verify");
              $("#orderCreatorNameBox select[name='orderCreatorName']").removeAttr("lay-verify");
              $('form[lay-filter="addProductionPlanForm"] input[name="demandQuantity"]').removeAttr("readonly");
            } else if (_data == "order") {
              $("#orderTypeBox").show({ duration: 300 });
              $("#orderIdBox").show({ duration: 300 });
              $("#orderCreatorNameBox").show({ duration: 300 });
              $("#residueQuantityBox").show({ duration: 300 });
              $("#orderRemarkBox").show({ duration: 300 });
              $("#signOrNotBox").show({ duration: 300 });
              $("#contractIdBox").show({ duration: 300 });

              // 交货时间
              $("#addProductionPlanDeliveryTime").attr("readonly", "");
              $("#addProductionPlanDeliveryTime").attr("disabled", "");

              $("#addProductionPlanDeliveryTime").removeAttr("lay-verify");

              $("#orderIdBox select[name='orderId']").attr("lay-verify", "required");
              $("#orderTypeBox select[name='orderType']").attr("lay-verify", "required");
              $("#orderCreatorNameBox select[name='orderCreatorName']").attr("lay-verify", "required");
              $('form[lay-filter="addProductionPlanForm"] input[name="demandQuantity"]').attr("readonly", "");
            }
            form.render("select");
          }

          // 是否已签约下拉方法 （控制所属合同选项的隐藏显示）
          /*  function signOrNotFun(_data) {
                            if (_data == 'yes') {
                                $('#contractIdBox').show({duration: 300});
                                $('#contractId').attr('lay-verify', 'required');
                            } else if (_data == 'no') {
                                $('#contractIdBox').hide({duration: 300});
                                $('#contractId').val('');
                                $('#contractId').removeAttr('lay-verify');
                            }
                            form.render("select");
                        }*/

          // 计划性质下拉方法（控制工序的显示隐藏）
          function planNatureFun(_data) {
            if (_data == "entirety") {
              $("#processIdBox").hide({ duration: 300 });
              $('#processIdBox select[name="processId"]').removeAttr("lay-verify");
            } else if (_data == "process") {
              $("#processIdBox").show({ duration: 300 });
              $('#processIdBox select[name="processId"]').attr("lay-verify", "required");
            }
          }

          function orderIdFun(_data) {
            if (_data && _data != "") {
              $("form[lay-filter='addProductionPlanForm'] input[name='orderRemark']").val($(_data.elem).find("option:selected").attr("orderremark"));
              $("form[lay-filter='addProductionPlanForm'] input[name='shipmentTime']").val($(_data.elem).find("option:selected").attr("deliverytime"));
              $("form[lay-filter='addProductionPlanForm'] input[name='orderCreatorName']").val($(_data.elem).find("option:selected").attr("ordercreatorname"));
              // $("form[lay-filter='addProductionPlanForm'] input[name='signOrNot']").val($(_data.elem).find("option:selected").attr("signornot"));
              $("form[lay-filter='addProductionPlanForm'] input[name='signOrNotDesc']").val($(_data.elem).find("option:selected").attr("signornotdesc"));
              $("form[lay-filter='addProductionPlanForm'] input[name='contractId']").val($(_data.elem).find("option:selected").attr("contractId"));
              $("form[lay-filter='addProductionPlanForm'] input[name='contractName']").val($(_data.elem).find("option:selected").attr("contractname"));
            } else {
              $("form[lay-filter='addProductionPlanForm'] input[name='orderRemark']").val("");
              $("form[lay-filter='addProductionPlanForm'] input[name='shipmentTime']").val("");
              $("form[lay-filter='addProductionPlanForm'] input[name='orderCreatorName']").val("");
              // $("form[lay-filter='addProductionPlanForm'] input[name='signOrNot']").val('');
              $("form[lay-filter='addProductionPlanForm'] input[name='signOrNotDesc']").val("");
              $("form[lay-filter='addProductionPlanForm'] input[name='contractId']").val("");
              $("form[lay-filter='addProductionPlanForm'] input[name='contractName']").val("");
            }
            form.render("select");
          }

          //物料列表
          $("#customerSkuCode").click(function () {
            //计划来源
            let planSource = $("#planSource").val();
            let orderId;
            if (planSource === "order") {
              orderId = $("#orderId").val();
              if (orderId === "" || orderId === undefined) {
                layer.msg("请选择订单编号", { icon: 2 });
                return false;
              }
            }
            admin.formOpen({
              area: ["80%", "85%"],
              offset: ["100px", "320px"],
              title: "物料列表",
              style: "font-size: 20px;",
              path: "components/productionPlan/product_detail.html",
              success: function () {
                parentData.orderId = orderId;
              }
            });
          });

          // 物料编号请求数据
          function customerSkuCodeGetDataFun(_data) {
            //    if (_data == 'temporary' || _data == 'research') {
            //        admin.reqSync('enterprise/product/admin/productDetail/list', {
            //            page: 1,
            //            limit: 9999
            //        }, function (res) {
            //            if (res.code == 200) {
            //                loadSelectHtml(res.data, '请选择物料编号', 'customerSkuCode', 'addProductionPlanForm', 2)
            //            }
            //        }, 'GET');
            //    } else if (_data == 'order') {
            //        loadSelectHtml([], '请选择物料编号', 'customerSkuCode', 'addProductionPlanForm', 3);
            //        customerSkuCodeFun();
            //    } else if (!_data && _data == '') {
            //        loadSelectHtml([], '请选择物料编号', 'customerSkuCode', 'addProductionPlanForm', 2);
            //    } else {
            //        admin.reqSync('enterprise/sell/admin/orderPro/getOrderProVOListByOrderId', {
            //            orderId: _data,
            //            page: 1,
            //            limit: 9999
            //        }, function (res) {
            //            if (res.code == 200) {
            //                loadSelectHtml(res.data, '请选择物料编号', 'customerSkuCode', 'addProductionPlanForm', 3)
            //            }
            //        }, 'GET');
            //    }
          }

          //请求工序的数据
          //  function getProcessIdData(productDetailId) {
          //    if (productDetailId && productDetailId != '') {
          //      admin.initDataSelect('enterprise/echnologyParam/admin/echnologyParam/list', { productDetailId: productDetailId }, null, '工序', null, null);
          //    }
          //  }
          if (data && data.id) {
            await admin.initDataSelectPro(
              "enterprise/benchmarkBook/admin/benchmarkBook/getBookInfoBy/" + addProductionPlanData.productDetailId,
              {},
              "bookId",
              "基准书",
              async (d) => {
                await admin.initDataSelectPro("enterprise/benchmarkBook/admin/benchmarkBook/getEchnologyBy/" + d.value, {}, "processId", "工序", () => {
                  console.log(123);
                });
              },
              "code"
            );
            await admin.initDataSelectPro("enterprise/benchmarkBook/admin/benchmarkBook/getEchnologyBy/" + addProductionPlanData.bookId, {}, "processId", "工序", () => {
              console.log(222);
            });
          }
          if (data) {
            setTimeout(function () {
              form.val("addProductionPlanForm", addProductionPlanData);
              form.render("select");
            }, 300);
          }

          // 表单提交事件
          // 暂时保存
          form.on("submit(addProductionPlanFormSubmit)", function (d) {
            layer.load(2);
            data ? (d.field.status = "toconfirmed") : "";
            if (d.field.planSource == "order" && parseInt(d.field.productionQuantity) > parseInt(d.field.residueQuantity)) {
              layer.confirm(
                "计划生产数量大于订单剩余计划数量是否继续",
                {
                  icon: 3,
                  title: "提示",
                  btn: ["提交", "取消"]
                },
                function (index) {
                  admin.req(
                    data ? "production/productionPlan/admin/productionPlan/update" : "production/productionPlan/admin/productionPlan/add",
                    d.field,
                    function (res) {
                      layer.closeAll("loading");
                      if (res.code == 200) {
                        layer.msg(res.msg, { icon: 1 });
                        table.reload("productionPlanTable");
                        layer.closeAll("page");
                      } else {
                        layer.msg(res.msg, { icon: 2 });
                      }
                    },
                    data ? "PUT" : "POST"
                  );
                  layer.close(index);
                },
                function (index) {
                  layer.msg("已取消");
                  layer.closeAll("loading");
                }
              );
            } else {
              admin.req(
                data ? "production/productionPlan/admin/productionPlan/update" : "production/productionPlan/admin/productionPlan/add",
                d.field,
                function (res) {
                  layer.closeAll("loading");
                  if (res.code == 200) {
                    layer.msg(res.msg, { icon: 1 });
                    table.reload("productionPlanTable");
                    layer.closeAll("page");
                  } else {
                    layer.msg(res.msg, { icon: 2 });
                  }
                },
                data ? "PUT" : "POST"
              );
            }

            return false;
          });

          // 确认提交
          form.on("submit(addProductionPlanExamine)", function (d) {
            layer.load(2);
            data ? (d.field.status = "affirm") : "";
            if (d.field.planSource == "order" && parseInt(d.field.productionQuantity) > parseInt(d.field.residueQuantity)) {
              layer.confirm(
                "计划生产数量大于订单剩余计划数量是否继续",
                {
                  icon: 3,
                  title: "提示",
                  btn: ["提交", "取消"]
                },
                function (index) {
                  admin.req(
                    data ? "production/productionPlan/admin/productionPlan/update" : "production/productionPlan/admin/productionPlan/add",
                    d.field,
                    function (res) {
                      layer.closeAll("loading");
                      if (res.code == 200) {
                        layer.msg(res.msg, { icon: 1 });
                        table.reload("productionPlanTable");
                        layer.closeAll("page");
                      } else {
                        layer.msg(res.msg, { icon: 2 });
                      }
                    },
                    data ? "PUT" : "POST"
                  );
                  layer.close(index);
                },
                function (index) {
                  layer.msg("已取消");
                  layer.closeAll("loading");
                }
              );
            } else {
              admin.req(
                data ? "production/productionPlan/admin/productionPlan/update" : "production/productionPlan/admin/productionPlan/add",
                d.field,
                function (res) {
                  layer.closeAll("loading");
                  if (res.code == 200) {
                    layer.msg(res.msg, { icon: 1 });
                    table.reload("productionPlanTable");
                    layer.closeAll("page");
                  } else {
                    layer.msg(res.msg, { icon: 2 });
                  }
                },
                data ? "PUT" : "POST"
              );
            }
            return false;
          });
        }
      });
    }

    // examineProductionPlan
    //审核生产计划
    function examineProductionPlanModel(data, _type) {
      admin.open({
        type: 1,
        area: ["1600px", "85%"],
        title: _type == "examine" ? "生产计划审核" : "生产计划详情",
        content: $("#examineProductionPlanForm").html(),
        success: function () {
          if (_type == "details") {
            $("#examineBox").hide();
            $('form[lay-filter="examineProductionPlanForm"] button[lay-filter="examineProductionPlanFormSubmit"]').hide();
          }
          let examineProductionPlanFormData = [];
          admin.reqSync(
            "production/productionPlan/admin/productionPlan/getProductionPlanInfoById",
            { id: data.id },
            (res) => {
              if (res.code === 200) {
                examineProductionPlanFormData = res.data;
              }
            },
            "get"
          );
          examineProductionPlanFormData.auditPerson = config.getUser().username;
          if (examineProductionPlanFormData.planSource !== "order") {
            $("#orderCodeDiv").hide();
            $("#signOrNotDiv").hide();
            $("#contractDiv").hide();
          }
          form.val("examineProductionPlanForm", examineProductionPlanFormData.planData[0]);
          $("#accessoryImg").attr("src", examineProductionPlanFormData.planData[0].accessory);
          form.render("select");

          let examineProductionPlanTb = table.render({
            elem: "#examineProductionPlanTable",
            data: examineProductionPlanFormData.planData,
            page: false,
            cellMinWidth: 100,
            cols: [
              [
                {
                  field: "code",
                  align: "center",
                  title: "计划编号",
                  width: 150
                },
                // { field: "categoryName", align: "center", title: "计划分类" },
                { field: "typeName", align: "center", title: "计划类型" },
                {
                  field: "planNatureDesc",
                  align: "center",
                  title: "计划性质"
                },
                { field: "demandQuantity", align: "center", title: "需求量" },
                {
                  field: "surplusQuantity",
                  align: "center",
                  title: "剩余计划量"
                },
                {
                  field: "productionQuantity",
                  align: "center",
                  title: "本计划生产量"
                },
                {
                  field: "outputTime",
                  align: "center",
                  title: "计划产出时间",
                  width: 160
                },
                {
                  field: "creatorName",
                  align: "center",
                  title: "计划创建人",
                  width: 200,
                  templet: (d) => d.creatorName + "<br />电话：" + d.phone
                },
                {
                  field: "createTime",
                  align: "center",
                  title: "计划时间",
                  width: 160
                }
              ]
            ]
          });
          let auditRecordsTb = table.render({
            elem: "#auditRecordsTable",
            data: examineProductionPlanFormData.auditData,
            page: false,
            cellMinWidth: 100,
            cols: [
              [
                {
                  type: "numbers",
                  align: "center",
                  title: "序号",
                  width: 80
                },
                { field: "creatorName", align: "center", title: "审核人" },
                {
                  field: "checkStatusDesc",
                  align: "center",
                  title: "审核结果"
                },
                { field: "remark", align: "center", title: "审核备注" },
                { field: "createTime", align: "center", title: "审核时间" }
              ]
            ]
          });

          form.on("submit(examineProductionPlanFormSubmit)", function (d) {
            layer.load(2);
            d.field.id = data.id;
            admin.req(
              "production/productionPlan/admin/productionPlan/auditPlan",
              d.field,
              function (res) {
                layer.closeAll("loading");
                if (res.code == 200) {
                  layer.msg(res.msg, { icon: 1 });
                  table.reload("productionPlanTable");
                  layer.closeAll("page");
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              "PUT"
            );
            return false;
          });
        }
      });
    }

    // 作废
    function toVoidToolCabinet(_data) {
      layer.confirm(
        "确定作废吗？",
        {
          skin: "layui-layer-admin"
        },
        function (i) {
          layer.close(i);
          layer.load(2);
          admin.req(
            "production/productionPlan/admin/productionPlan/cancellation",
            { id: _data.id },
            function (data) {
              layer.closeAll("loading");
              if (data.code == 200) {
                layer.msg(data.msg, { icon: 1 });
                table.reload("productionPlanTable");
                layer.closeAll("page");
              } else {
                layer.msg(data.msg, { icon: 2 });
              }
            },
            "PUT"
          );
        }
      );
    }

    //上传附件
    function uploadFile(_elem, pathId, inputId) {
      upload.render({
        elem: "#" + _elem,
        url: config.upload_url + "uploadFile",
        data: {},
        accept: "file",
        exts: "jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx|apk",
        headers: { Authorization: "Bearer " + config.getToken() },
        done: function (res) {
          if (res.code == 200) {
            layer.msg(res.msg || "上传成功", { icon: 1 });
            let imagUrl = res.data.url;
            $("#" + pathId).html("<a href='" + imagUrl + "' target='_blank'>" + imagUrl + "</a>");
            $("#" + inputId).val(imagUrl);
          } else if (res.code == 502) {
            return location.replace("admin/login.html");
          } else {
            layer.msg(res.msg || "上传失败", { icon: 2 });
          }
        }
      });
    }

    // 渲染下拉框数据
    function loadSelectHtml(data, tips, htmltarget, formName, type) {
      let html = " <option value>" + tips + "</option>";
      if (!data || data == null) {
        return;
      }
      for (let i = 0; i < data.length; i++) {
        if (type == 1) {
          html += `<option value='${data[i].id}'>${data[i].name}</option>`;
        } else if (type == 2) {
          html += `<option
                                  value='${data[i].skuCode}'
                                  productDetailId='${data[i].id}'
                                  skuName='${data[i].skuName}'
                                  skuSpec='${data[i].skuSpec}'
                                  productTypeId ='${data[i].productTypeId}'
                                  productTypeName ='${data[i].productTypeName}'
                                 >${data[i].skuCode}</option>`;
        } else if (type == 3) {
          html += `<option
                                  value='${data[i].id}'
                                  skuName='${data[i].customerSkuName}'
                                  skuSpec='${data[i].customerSpecCode}'
                                  residueQuantity='${data[i].residueQuantity}'
                                  quantity='${data[i].quantity}'
                                  orderProId='${data[i].id}'
                                  customerSkuItem = '${data[i].customerSkuItem}'
                                  productTypeId ='${data[i].proTypeId}'
                                  productTypeName ='${data[i].productTypeName}'
                                 >${data[i].customerSkuItem}</option>`;
        } else if (type == 4) {
          html += `<option
                                  value='${data[i].id}'
                                  deliveryTime='${data[i].deliveryTime}'
                                  orderRemark='${data[i].orderRemark}'
                                  orderCreatorName='${data[i].orderCreatorName}'
                                  signOrNot='${data[i].status}'
                                  signOrNotDesc='${data[i].statusDesc}'
                                  contractName='${data[i].contractName}'
                                  contractId='${data[i].contractId}'
                                  >${data[i].code}</option>`;
        } else if (type == 5) {
          html += `<option value='${data[i].id}'>${data[i].nodeNames}</option>`;
        } else {
          html += `<option value='${data[i].id}'>${data[i].name}</option>`;
        }
      }
      $("form[lay-filter='" + formName + "'] select[name='" + htmltarget + "']").html(html);
      form.render("select");
    }
  });
</script>
